我想在 zxing 捕获屏幕(相机屏幕)周围放置自定义边框。为此我需要进行哪些修改?我需要更改哪些活动和布局才能产生这种效果?
问问题
15811 次
4 回答
12
您根本不需要编辑布局。
在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);
于 2011-05-14T21:49:14.053 回答
5
这个问题已经有了答案。但是如果有人需要如何在捕获屏幕周围绘制边框,这里是代码。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);
于 2018-05-27T20:09:49.170 回答
1
实际上,您可以在自己的 colors.xml 文件中覆盖颜色,即
<color name="viewfinder_border">#00d1cf</color>
于 2017-05-24T05:54:12.127 回答