[英]ZXing Barcode Reader: How to make custom border around capture screen?
我想在 zxing 捕获屏幕(相机屏幕)周围放置自定义边框。 为此我需要进行哪些修改? 我需要更改哪些活动和布局才能产生这种效果?
您根本不需要编辑布局。
在ViewfinderView
中找到onDraw
方法。 它是绘制“扫描矩形”的核心。 你可以按照你想要的方式修改它。
实际绘制矩形的代码可以在这里找到:
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
实际上,您可以在自己的 colors.xml 文件中覆盖颜色,即
<color name="viewfinder_border">#00d1cf</color>
这个问题已经有了答案。 但是如果有人需要如何在捕获屏幕周围绘制边框,这里是代码。 inazaruk 的回答是正确的。 我的回答只是对此的延伸。
//initialize new paint in the constructor
Paint borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
borderPaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
//inside onDraw
int distance = (frame.bottom - frame.top) / 4;
int thickness = 15;
//top left corner
canvas.drawRect(frame.left - thickness, frame.top - thickness, distance + frame.left, frame.top, borderPaint);
canvas.drawRect(frame.left - thickness, frame.top, frame.left, distance + frame.top, borderPaint);
//top right corner
canvas.drawRect(frame.right - distance, frame.top - thickness, frame.right + thickness, frame.top, borderPaint);
canvas.drawRect(frame.right, frame.top, frame.right + thickness, distance + frame.top, borderPaint);
//bottom left corner
canvas.drawRect(frame.left - thickness, frame.bottom, distance + frame.left, frame.bottom + thickness, borderPaint);
canvas.drawRect(frame.left - thickness, frame.bottom - distance, frame.left, frame.bottom, borderPaint);
//bottom right corner
canvas.drawRect(frame.right - distance, frame.bottom, frame.right + thickness, frame.bottom + thickness, borderPaint);
canvas.drawRect(frame.right, frame.bottom - distance, frame.right + thickness, frame.bottom, borderPaint);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.