ZXing条形码阅读器:如何在捕获屏幕周围制作自定义边框?

时间:2011-05-01 23:03:34

标签: java android user-interface zxing

我想在zxing捕捉屏幕(相机屏幕)周围放置自定义边框。我需要做些什么修改?我需要更改哪些活动和布局才能产生这种效果?

4 个答案:

答案 0 :(得分:12)

您根本不需要编辑布局。

ViewfinderView查找onDraw方法中。它是绘制“扫描矩形”的核心。您可以按照自己的方式进行修改。

可以找到实际绘制矩形的代码here

// 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);

答案 1 :(得分:3)

Here是其他一些人如此做到的。

另外看here,它看起来很有用。

最后,我会使用this一个。

答案 2 :(得分:1)

实际上你可以覆盖你自己的colors.xml文件中的颜色,即

<color name="viewfinder_border">#00d1cf</color>

答案 3 :(得分:1)

这个问题已经有了答案。但如果有人需要如何在捕获屏幕周围绘制边框,这里是代码。 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);

enter image description here