优化细节
This commit is contained in:
@@ -193,7 +193,7 @@ CameraScan配置示例(只需识别二维码的配置示例)
|
|||||||
```java
|
```java
|
||||||
//初始化解码配置
|
//初始化解码配置
|
||||||
DecodeConfig decodeConfig = new DecodeConfig();
|
DecodeConfig decodeConfig = new DecodeConfig();
|
||||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高
|
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||||
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
||||||
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||||
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class QRCodeActivity extends CaptureActivity {
|
|||||||
|
|
||||||
//初始化解码配置
|
//初始化解码配置
|
||||||
DecodeConfig decodeConfig = new DecodeConfig();
|
DecodeConfig decodeConfig = new DecodeConfig();
|
||||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高
|
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||||
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
||||||
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||||
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
||||||
|
|||||||
@@ -458,7 +458,7 @@ public class ViewfinderView extends View {
|
|||||||
* @param frame
|
* @param frame
|
||||||
*/
|
*/
|
||||||
private void drawLaserScanner(Canvas canvas, Rect frame) {
|
private void drawLaserScanner(Canvas canvas, Rect frame) {
|
||||||
if(laserStyle!=null){
|
if(laserStyle != null){
|
||||||
paint.setColor(laserColor);
|
paint.setColor(laserColor);
|
||||||
switch (laserStyle){
|
switch (laserStyle){
|
||||||
case LINE://线
|
case LINE://线
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析二维码图片
|
* 解析二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String parseQRCode(String bitmapPath){
|
public static String parseQRCode(String bitmapPath){
|
||||||
@@ -255,7 +255,7 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析二维码图片
|
* 解析二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Result parseQRCodeResult(String bitmapPath){
|
public static Result parseQRCodeResult(String bitmapPath){
|
||||||
@@ -264,9 +264,9 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析二维码图片
|
* 解析二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @param reqWidth
|
* @param reqWidth 请求目标宽度,如果实际图片宽度大于此值,会自动进行压缩处理,当 reqWidth 和 reqHeight都小于或等于0时,则不进行压缩处理
|
||||||
* @param reqHeight
|
* @param reqHeight 请求目标高度,如果实际图片高度大于此值,会自动进行压缩处理,当 reqWidth 和 reqHeight都小于或等于0时,则不进行压缩处理
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Result parseQRCodeResult(String bitmapPath,int reqWidth,int reqHeight){
|
public static Result parseQRCodeResult(String bitmapPath,int reqWidth,int reqHeight){
|
||||||
@@ -275,7 +275,7 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析一维码/二维码图片
|
* 解析一维码/二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String parseCode(String bitmapPath){
|
public static String parseCode(String bitmapPath){
|
||||||
@@ -284,7 +284,7 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析一维码/二维码图片
|
* 解析一维码/二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @param hints 解析编码类型
|
* @param hints 解析编码类型
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -308,9 +308,9 @@ public final class CodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析一维码/二维码图片
|
* 解析一维码/二维码图片
|
||||||
* @param bitmapPath
|
* @param bitmapPath 需要解析的图片路径
|
||||||
* @param reqWidth
|
* @param reqWidth 请求目标宽度,如果实际图片宽度大于此值,会自动进行压缩处理,当 reqWidth 和 reqHeight都小于或等于0时,则不进行压缩处理
|
||||||
* @param reqHeight
|
* @param reqHeight 请求目标高度,如果实际图片高度大于此值,会自动进行压缩处理,当 reqWidth 和 reqHeight都小于或等于0时,则不进行压缩处理
|
||||||
* @param hints 解析编码类型
|
* @param hints 解析编码类型
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -366,6 +366,7 @@ public final class CodeUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static Bitmap compressBitmap(String path,int reqWidth,int reqHeight){
|
private static Bitmap compressBitmap(String path,int reqWidth,int reqHeight){
|
||||||
|
if(reqWidth > 0 && reqHeight > 0){//都大于进行判断是否压缩
|
||||||
|
|
||||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
||||||
// 开始读入图片,此时把options.inJustDecodeBounds 设回true了
|
// 开始读入图片,此时把options.inJustDecodeBounds 设回true了
|
||||||
@@ -388,7 +389,12 @@ public final class CodeUtils {
|
|||||||
newOpts.inSampleSize = size;// 设置缩放比例
|
newOpts.inSampleSize = size;// 设置缩放比例
|
||||||
// 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
|
// 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
|
||||||
newOpts.inJustDecodeBounds = false;
|
newOpts.inJustDecodeBounds = false;
|
||||||
|
|
||||||
return BitmapFactory.decodeFile(path, newOpts);
|
return BitmapFactory.decodeFile(path, newOpts);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return BitmapFactory.decodeFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ ext.deps = [:]
|
|||||||
// App dependencies
|
// App dependencies
|
||||||
def versions = [:]
|
def versions = [:]
|
||||||
//AndroidX
|
//AndroidX
|
||||||
versions.material = "1.2.0-alpha01"
|
versions.material = "1.2.0"
|
||||||
versions.appcompat = "1.1.0"
|
versions.appcompat = "1.1.0"
|
||||||
versions.constraintLayout = "1.1.3"
|
versions.constraintLayout = "1.1.3"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user