优化细节

This commit is contained in:
Jenly
2021-01-14 16:27:31 +08:00
parent 4ad01a3ba4
commit 95d129f53f
5 changed files with 41 additions and 35 deletions

View File

@@ -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表示居中可以为负数

View File

@@ -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表示居中可以为负数

View File

@@ -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://线

View File

@@ -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,29 +366,35 @@ 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();
// 开始读入图片此时把options.inJustDecodeBounds 设回true了
newOpts.inJustDecodeBounds = true;//获取原始图片大小
BitmapFactory.decodeFile(path, newOpts);// 此时返回bm为空
float width = newOpts.outWidth;
float height = newOpts.outHeight;
// 缩放比,由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
int wSize = 1;// wSize=1表示不缩放
if (width > reqWidth) {// 如果宽度大的话根据宽度固定大小缩放
wSize = (int) (width / reqWidth);
}
int hSize = 1;// wSize=1表示不缩放
if (height > reqHeight) {// 如果高度高的话根据宽度固定大小缩放
hSize = (int) (height / reqHeight);
}
int size = Math.max(wSize,hSize);
if (size <= 0)
size = 1;
newOpts.inSampleSize = size;// 设置缩放比例
// 重新读入图片注意此时已经把options.inJustDecodeBounds 设回false了
newOpts.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, newOpts);
BitmapFactory.Options newOpts = new BitmapFactory.Options();
// 开始读入图片此时把options.inJustDecodeBounds 设回true了
newOpts.inJustDecodeBounds = true;//获取原始图片大小
BitmapFactory.decodeFile(path, newOpts);// 此时返回bm为空
float width = newOpts.outWidth;
float height = newOpts.outHeight;
// 缩放比,由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
int wSize = 1;// wSize=1表示不缩放
if (width > reqWidth) {// 如果宽度大的话根据宽度固定大小缩放
wSize = (int) (width / reqWidth);
} }
int hSize = 1;// wSize=1表示不缩放
if (height > reqHeight) {// 如果高度高的话根据宽度固定大小缩放 return BitmapFactory.decodeFile(path);
hSize = (int) (height / reqHeight);
}
int size = Math.max(wSize,hSize);
if (size <= 0)
size = 1;
newOpts.inSampleSize = size;// 设置缩放比例
// 重新读入图片注意此时已经把options.inJustDecodeBounds 设回false了
newOpts.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, newOpts);
} }

View File

@@ -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"