And*_*der 8 java user-interface android zxing
我想在zxing捕捉屏幕(相机屏幕)周围放置自定义边框.我需要做些什么修改?我需要更改哪些活动和布局才能产生这种效果?
ina*_*ruk 12
您根本不需要编辑布局.
在ViewfinderViewfind 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);
Run Code Online (Sandbox Code Playgroud)
这个问题已经有答案了。但如果有人需要如何在捕获屏幕周围绘制边框,这里是代码。伊纳扎鲁克的回答是正确的。我的回答只是对此的延伸。
//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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12798 次 |
| 最近记录: |