1、支持真实识别区域比例和识别区域偏移量可配置
2、对外暴露更多可配置参数
This commit is contained in:
@@ -21,16 +21,18 @@ import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.Camera;
|
||||
import android.media.FaceDetector;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||
import com.king.zxing.camera.open.OpenCamera;
|
||||
import com.king.zxing.camera.open.OpenCameraInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.annotation.FloatRange;
|
||||
|
||||
/**
|
||||
* This object wraps the Camera service object and expects to be the only one talking to it. The
|
||||
* implementation encapsulates the steps needed to take preview-sized images, which are used for
|
||||
@@ -61,6 +63,10 @@ public final class CameraManager {
|
||||
private int requestedFramingRectHeight;
|
||||
private boolean isFullScreenScan;
|
||||
|
||||
private float framingRectRatio;
|
||||
private int framingRectVerticalOffset;
|
||||
private int framingRectHorizontalOffset;
|
||||
|
||||
/**
|
||||
* Preview frames are delivered here, which we pass on to the registered handler. Make sure to
|
||||
* clear the handler so it will only receive one message.
|
||||
@@ -235,10 +241,10 @@ public final class CameraManager {
|
||||
if(isFullScreenScan){
|
||||
framingRect = new Rect(0,0,width,height);
|
||||
}else{
|
||||
int size = Math.min(width,height);
|
||||
int size = (int)(Math.min(width,height) * framingRectRatio);
|
||||
|
||||
int leftOffset = (width - size) / 2;
|
||||
int topOffset = (height - size) / 2;
|
||||
int leftOffset = (width - size) / 2 + framingRectHorizontalOffset;
|
||||
int topOffset = (height - size) / 2 + framingRectVerticalOffset;
|
||||
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
|
||||
}
|
||||
|
||||
@@ -284,14 +290,22 @@ public final class CameraManager {
|
||||
return framingRectInPreview;
|
||||
}
|
||||
|
||||
public boolean isFullScreenScan() {
|
||||
return isFullScreenScan;
|
||||
}
|
||||
|
||||
public void setFullScreenScan(boolean fullScreenScan) {
|
||||
isFullScreenScan = fullScreenScan;
|
||||
}
|
||||
|
||||
public void setFramingRectRatio(@FloatRange(from = 0.0f ,to = 1.0f) float framingRectRatio) {
|
||||
this.framingRectRatio = framingRectRatio;
|
||||
}
|
||||
|
||||
public void setFramingRectVerticalOffset(int framingRectVerticalOffset) {
|
||||
this.framingRectVerticalOffset = framingRectVerticalOffset;
|
||||
}
|
||||
|
||||
public void setFramingRectHorizontalOffset(int framingRectHorizontalOffset) {
|
||||
this.framingRectHorizontalOffset = framingRectHorizontalOffset;
|
||||
}
|
||||
|
||||
public Point getCameraResolution() {
|
||||
return configManager.getCameraResolution();
|
||||
}
|
||||
@@ -355,9 +369,9 @@ public final class CameraManager {
|
||||
if(isFullScreenScan){
|
||||
return new PlanarYUVLuminanceSource(data,width,height,0,0,width,height,false);
|
||||
}
|
||||
int size = Math.min(width,height);
|
||||
int left = (width-size)/2;
|
||||
int top = (height-size)/2;
|
||||
int size = (int)(Math.min(width,height) * framingRectRatio);
|
||||
int left = (width-size)/2 + framingRectHorizontalOffset;
|
||||
int top = (height-size)/2 + framingRectVerticalOffset;
|
||||
// Go ahead and assume it's YUV rather than die.
|
||||
return new PlanarYUVLuminanceSource(data, width, height, left, top,
|
||||
size, size, false);
|
||||
|
||||
Reference in New Issue
Block a user