Skip to content

Commit

Permalink
提高解码区域精度
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiwean committed Jun 16, 2019
1 parent 4ca09f6 commit f27f2d7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
3 changes: 1 addition & 2 deletions lib/src/main/java/com/wishzixing/lib/able/AutoZoomAble.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ public void cusAction(final byte[] data, final Camera camera, final int x, final

ResultPoint[] p = detectorResult.getPoints();


//计算扫描框中的二维码的宽度,两点间距离公式
float point1X = p[0].getX();
float point1Y = p[0].getY();
float point2X = p[1].getX();
float point2Y = p[1].getY();


Log.e("1X:" + point1Y, "2Y:" + point2Y);
Log.e("size:", p.length + "");

float len = (int) Math.sqrt(Math.abs(point1X - point2X) * Math.abs(point1X - point2X) + Math.abs(point1Y - point2Y) * Math.abs(point1Y - point2Y));

Expand Down
13 changes: 11 additions & 2 deletions lib/src/main/java/com/wishzixing/lib/config/CameraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.graphics.Point;
import android.graphics.Rect;

import com.google.zxing.BinaryBitmap;

/***
* Created by SWY
* DATE 2019/6/1
Expand Down Expand Up @@ -78,4 +76,15 @@ public String getPreviewFormatString() {
public int getTenDesiredZoom() {
return tenDesiredZoom;
}

public boolean isPorScreen() {
if (screenPoint == null)
try {
throw new Exception("未获取到屏幕尺寸信息");
} catch (Exception e) {
e.printStackTrace();
}
return screenPoint.x < screenPoint.y;
}

}
39 changes: 31 additions & 8 deletions lib/src/main/java/com/wishzixing/lib/config/ParseRectConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wishzixing.lib.config;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;

/***
Expand All @@ -12,6 +11,7 @@
public class ParseRectConfig {

Rect parseRect;
private View v;

private ParseRectConfig() {

Expand All @@ -26,11 +26,7 @@ public static ParseRectConfig getInstance() {
}

public ParseRectConfig setParseRectFromView(final View view) {
int left = (int) view.getX();
int top = (int) view.getY();
int right = left + view.getMeasuredWidth();
int bottom = top + view.getMeasuredHeight();
parseRect = new Rect(left, top, right, bottom);
this.v = view;
return this;
}

Expand All @@ -44,11 +40,38 @@ public ParseRectConfig setParseRect(int left, int top, int right, int bottom) {
return this;
}

public void go() {
/***
* 初始化时生成合适的解析窗口大小
*/
private void creat() {

int cameraX = CameraConfig.getInstance().getCameraPoint().x;
int cameraY = CameraConfig.getInstance().getCameraPoint().y;

if (CameraConfig.getInstance().isPorScreen()) {
int tem = cameraX;
cameraX = cameraY;
cameraY = tem;
}

float ratioX = (float) cameraX / CameraConfig.getInstance().getScreenPoint().x;
float ratioY = (float) cameraY / CameraConfig.getInstance().getScreenPoint().y;

int left = (int) ((int) v.getX() * ratioX);
int top = (int) ((int) v.getY() * ratioY);
int right = left + v.getMeasuredWidth();
right *= ratioX;
int bottom = top + v.getMeasuredHeight();
bottom *= ratioY;

parseRect = new Rect(left, top, right, bottom);

}

public void go() {
creat();
if (parseRect == null)
parseRect = new Rect(0, 0, 0, 0);

CameraConfig.getInstance().parseRect = this.parseRect;
}
}
4 changes: 3 additions & 1 deletion lib/src/main/java/com/wishzixing/lib/config/PointConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ private PointConfig() {
initCameraPoint();
}


private static class Holder {
static PointConfig INSTANCE = new PointConfig();
}
Expand Down Expand Up @@ -80,6 +79,9 @@ private Point getCameraResolution(Camera.Parameters parameters, Point screenReso
previewSizeValueString = parameters.get("preview-size-value");
}

Log.e("preViewSizeValueString:", previewSizeValueString);


previewFormat = parameters.getPreviewFormat();
previewFormatString = parameters.get("preview-format");

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/wishzixing/lib/views/WishView.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public void scanImgFail() {
@Override
public void onCreate(Activity activity) {
get = new WeakReference<>(activity);
initView();
PermissionUtils.init(get.get());
initView();
wishViewDelegate.onCreate(activity);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public WishViewDelegate setParseRectFromView(final View view) {
view.post(new Runnable() {
@Override
public void run() {
ParseRectConfig.getInstance().setParseRectFromView(view).go();
ParseRectConfig.getInstance().setParseRectFromView(view);
}
});
return this;
Expand Down

0 comments on commit f27f2d7

Please sign in to comment.