Zxing框架扫描框大小适配问题
zxing
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
项目地址:https://gitcode.com/gh_mirrors/zx/zxing
免费下载资源
·
Zxing框架进行二维码扫描时候会发现,随着分辨率的增加,扫描框会越来越小,SurfaceView扫描窗口就看不见了,我们可以自己定义扫描窗口的大小,以及适配屏幕问题。
Zxing包中有个类CameraManager,它是来设置扫描框的大小
扫描框框初始化数值
private static int MIN_FRAME_WIDTH = 240;
private static int MIN_FRAME_HEIGHT = 240;
private static int MAX_FRAME_WIDTH = 480;
private static int MAX_FRAME_HEIGHT = 360;
此类里面有个getFramingRect方法用来设置扫描的框的大小
,如果要修改扫描框的大小可以在这个方法里修改
public Rect getFramingRect() {
Point screenResolution = configManager.getScreenResolution();
if (framingRect == null) {
if (camera == null) {
return null;
}
int width = screenResolution.x * 3 / 4;
if (width < MIN_FRAME_WIDTH) {
width = MIN_FRAME_WIDTH;
} else if (width > MAX_FRAME_WIDTH) {
width = MAX_FRAME_WIDTH;
}
int height = screenResolution.y * 3 / 4;
if (height < MIN_FRAME_HEIGHT) {
height = MIN_FRAME_HEIGHT;
}
else if (height > MAX_FRAME_HEIGHT) {
height = MAX_FRAME_HEIGHT;
}
int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
Log.d(TAG, "Calculated framing rect: " + framingRect);
}
return framingRect;
}
要让扫描框适应不同的分辨率,我们需要根据分辨率将扫描矿的初始值转化就好。
MIN_FRAME_WIDTH = Dp2Px(context,180);
MIN_FRAME_HEIGHT =Dp2Px(context,180) ;
MAX_FRAME_WIDTH = Dp2Px(context,280);
MAX_FRAME_HEIGHT =Dp2Px(context,240) ;
dp转为px的方法为
public static int Dp2Px( Context context,float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
GitHub 加速计划 / zx / zxing
32.53 K
9.31 K
下载
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
最近提交(Master分支:2 个月前 )
8944e607
3 个月前
6ea3726b
Bumps `spring.version` from 6.1.5 to 6.1.8.
Updates `org.springframework:spring-test` from 6.1.5 to 6.1.8
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.5...v6.1.8)
Updates `org.springframework:spring-web` from 6.1.5 to 6.1.8
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.5...v6.1.8)
---
updated-dependencies:
- dependency-name: org.springframework:spring-test
dependency-type: direct:development
update-type: version-update:semver-patch
- dependency-name: org.springframework:spring-web
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sean Owen <srowen@gmail.com> 3 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)