Skip to content

Commit

Permalink
修复近距离扫描解析不出来的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhiqiang1993 committed Jan 7, 2019
1 parent 74baaf0 commit ce8646b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/com/yzq/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;
import com.yzq.zxinglibrary.encode.CodeCreator;

Expand Down Expand Up @@ -108,15 +109,15 @@ public void onAction(List<String> permissions) {
* 设置扫描框颜色等
* 也可以不传这个参数
* */
// ZxingConfig config = new ZxingConfig();
// config.setPlayBeep(false);//是否播放扫描声音 默认为true
// config.setShake(false);//是否震动 默认为true
// config.setDecodeBarCode(false);//是否扫描条形码 默认为true
ZxingConfig config = new ZxingConfig();
// config.setPlayBeep(false);//是否播放扫描声音 默认为true
// config.setShake(false);//是否震动 默认为true
// config.setDecodeBarCode(false);//是否扫描条形码 默认为true
// config.setReactColor(R.color.colorAccent);//设置扫描框四个角的颜色 默认为白色
// config.setFrameLineColor(R.color.colorAccent);//设置扫描框边框颜色 默认无色
// config.setScanLineColor(R.color.colorAccent);//设置扫描线的颜色 默认白色
// config.setFullScreenScan(false);//是否全屏扫描 默认为true 设为false则只会在扫描框中扫描
// intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
config.setFullScreenScan(false);//是否全屏扫描 默认为true 设为false则只会在扫描框中扫描
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
startActivityForResult(intent, REQUEST_CODE_SCAN);
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.SurfaceHolder;

import com.google.zxing.PlanarYUVLuminanceSource;
import com.yzq.zxinglibrary.R;
import com.yzq.zxinglibrary.android.CaptureActivityHandler;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;
Expand Down Expand Up @@ -360,8 +361,9 @@ public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data,
return new PlanarYUVLuminanceSource(data, width, height, 0,
0, width, height, false);
} else {
int actionbarHeight = context.getResources().getDimensionPixelSize(R.dimen.toolBarHeight);
return new PlanarYUVLuminanceSource(data, width, height, rect.left,
rect.top, rect.width(), rect.height(), false);
rect.top + actionbarHeight, rect.width(), rect.height(), false);
}


Expand Down
2 changes: 1 addition & 1 deletion zxinglibrary/src/main/res/layout/activity_capture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<RelativeLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_height="@dimen/toolBarHeight"
android:layout_gravity="top"
android:background="#99000000">

Expand Down
1 change: 1 addition & 0 deletions zxinglibrary/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="toolBarHeight">48dp</dimen>
</resources>

0 comments on commit ce8646b

Please sign in to comment.