优化部分已知细节问题
This commit is contained in:
@@ -58,7 +58,7 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
||||
|
||||
CaptureHandler(Activity activity,ViewfinderView viewfinderView,OnCaptureListener onCaptureListener,
|
||||
Collection<BarcodeFormat> decodeFormats,
|
||||
Map<DecodeHintType,?> baseHints,
|
||||
Map<DecodeHintType,Object> baseHints,
|
||||
String characterSet,
|
||||
CameraManager cameraManager) {
|
||||
this.activity = activity;
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
@@ -36,6 +35,7 @@ import com.king.zxing.camera.CameraManager;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
||||
private SurfaceHolder.Callback callback;
|
||||
|
||||
private Collection<BarcodeFormat> decodeFormats;
|
||||
private Map<DecodeHintType,?> decodeHints;
|
||||
private Map<DecodeHintType,Object> decodeHints;
|
||||
private String characterSet;
|
||||
|
||||
private boolean hasSurface;
|
||||
@@ -376,10 +376,10 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据范围限定值
|
||||
* @param x
|
||||
* @param min
|
||||
* @param max
|
||||
* @param min 范围最小值
|
||||
* @param max 范围最大值
|
||||
* @return
|
||||
*/
|
||||
private int clamp(int x, int min, int max) {
|
||||
@@ -504,7 +504,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
||||
|
||||
/**
|
||||
* 设置支持的解码一/二维码格式,默认常规的码都支持
|
||||
* @param decodeFormats
|
||||
* @param decodeFormats 可参见{@link DecodeFormatManager}
|
||||
* @return
|
||||
*/
|
||||
public CaptureHelper decodeFormats(Collection<BarcodeFormat> decodeFormats) {
|
||||
@@ -517,11 +517,25 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
||||
* @param decodeHints
|
||||
* @return
|
||||
*/
|
||||
public CaptureHelper decodeHints(Map<DecodeHintType,?> decodeHints) {
|
||||
public CaptureHelper decodeHints(Map<DecodeHintType,Object> decodeHints) {
|
||||
this.decodeHints = decodeHints;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DecodeHintType}
|
||||
* @param key {@link DecodeHintType}
|
||||
* @param value {@link }
|
||||
* @return
|
||||
*/
|
||||
public CaptureHelper decodeHint(DecodeHintType key,Object value){
|
||||
if(decodeHints == null){
|
||||
decodeHints = new EnumMap<>(DecodeHintType.class);
|
||||
}
|
||||
decodeHints.put(key,value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置解码时编码字符集
|
||||
* @param characterSet
|
||||
@@ -596,21 +610,37 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CameraManager}
|
||||
* @return {@link #cameraManager}
|
||||
*/
|
||||
@Override
|
||||
public CameraManager getCameraManager() {
|
||||
return cameraManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BeepManager}
|
||||
* @return {@link #beepManager}
|
||||
*/
|
||||
@Override
|
||||
public BeepManager getBeepManager() {
|
||||
return beepManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AmbientLightManager}
|
||||
* @return {@link #ambientLightManager}
|
||||
*/
|
||||
@Override
|
||||
public AmbientLightManager getAmbientLightManager() {
|
||||
return ambientLightManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link InactivityTimer}
|
||||
* @return {@link #inactivityTimer}
|
||||
*/
|
||||
@Override
|
||||
public InactivityTimer getInactivityTimer() {
|
||||
return inactivityTimer;
|
||||
|
||||
@@ -33,9 +33,12 @@ import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.king.zxing.camera.CameraManager;
|
||||
|
||||
@@ -103,17 +106,22 @@ final class DecodeHandler extends Handler {
|
||||
try {
|
||||
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||
} catch (Exception e) {
|
||||
if(isSupportVerticalCode){
|
||||
source = buildPlanarYUVLuminanceSource(data,width,height,!isScreenPortrait);
|
||||
if(source!=null){
|
||||
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
|
||||
try{
|
||||
rawResult = multiFormatReader.decodeWithState(bitmap1);
|
||||
}catch (Exception e1){
|
||||
BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
||||
try{
|
||||
rawResult = multiFormatReader.decodeWithState(bitmap1);
|
||||
}catch (Exception e1){
|
||||
if(isSupportVerticalCode){
|
||||
source = buildPlanarYUVLuminanceSource(data,width,height,!isScreenPortrait);
|
||||
if(source!=null){
|
||||
BinaryBitmap bitmap2 = new BinaryBitmap(new HybridBinarizer(source));
|
||||
try{
|
||||
rawResult = multiFormatReader.decodeWithState(bitmap2);
|
||||
}catch (Exception e2){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
@@ -55,7 +55,7 @@ final class DecodeThread extends Thread {
|
||||
DecodeThread(Context context,CameraManager cameraManager,
|
||||
CaptureHandler captureHandler,
|
||||
Collection<BarcodeFormat> decodeFormats,
|
||||
Map<DecodeHintType,?> baseHints,
|
||||
Map<DecodeHintType,Object> baseHints,
|
||||
String characterSet,
|
||||
ResultPointCallback resultPointCallback) {
|
||||
|
||||
|
||||
@@ -161,8 +161,6 @@ final class CameraConfigurationManager {
|
||||
parameters.setZoom(parameters.getMaxZoom() / 10);
|
||||
}
|
||||
|
||||
theCamera.setParameters(parameters);
|
||||
|
||||
initializeTorch(parameters, prefs, safeMode);
|
||||
|
||||
CameraConfigurationUtils.setFocus(
|
||||
|
||||
@@ -198,7 +198,8 @@ public class CodeUtils {
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
try {
|
||||
result = reader.decode(bitmap,hints);
|
||||
} catch (Exception e) {//解析失败则通过GlobalHistogramBinarizer 再试一次
|
||||
} catch (Exception e) {
|
||||
//解析失败则通过GlobalHistogramBinarizer 再试一次
|
||||
BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
||||
try {
|
||||
result = reader.decode(bitmap1);
|
||||
@@ -232,6 +233,7 @@ public class CodeUtils {
|
||||
decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS);
|
||||
decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS);
|
||||
|
||||
hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE);
|
||||
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
|
||||
return parseCode(bitmapPath,hints);
|
||||
}
|
||||
@@ -257,7 +259,7 @@ public class CodeUtils {
|
||||
BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
||||
try {
|
||||
result = reader.decodeWithState(bitmap1);
|
||||
} catch (NotFoundException ne) {
|
||||
} catch (Exception ne) {
|
||||
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user