ZXingLite
ZXingLite copied to clipboard
使用 vvLaserDrawable 方法设置扫描线图片时,设置的内容会超出扫描框的设定范围。
描述:
在使用 vvLaserDrawable 设置了扫描线的图片后,图片会错误的加载到扫描框之外的区域。
现象:
相关代码:
描述:
在使用 vvLaserDrawable 设置了扫描线的图片后,图片会错误的加载到扫描框之外的区域。
现象:
相关代码:
- 你这个自定义的扫描线比默认的扫描线高出不少,需设置
vvLaserLineHeight; - 提问提错地方了, ViewfinderView 是一个独立维护的库,隶属于:ViewfinderView
感谢解答,您提供的方案确实有用,但是在这之前我是通过重写 ViewfinderView 来实现的,具体代码如下:
自定义图片绘制:
四周边角弧度+取景框圆角
/**
* 绘制边角
*/
private void drawCorner(Canvas canvas, Rect frame) {
// 保存画笔当前状态
Paint.Style originalStyle = paint.getStyle();
float originalStrokeWidth = paint.getStrokeWidth();
int originalColor = paint.getColor();
Paint.Cap originalCap = paint.getStrokeCap();
// 设置画笔样式和颜色
paint.setColor(frameCornerColor);
paint.setStyle(Paint.Style.STROKE); // 使用描边样式
paint.setStrokeWidth(frameCornerStrokeWidth); // 设置线宽
paint.setStrokeCap(Paint.Cap.ROUND); // 设置线条末端为圆角
float cornerRadius = UtilKt.dp2Px(12); // 设置你希望的圆角半径
float cornerLength = frameCornerSize; // 每条线的长度
// 左上角
canvas.drawArc(new RectF(frame.left, frame.top, frame.left + 2 * cornerRadius, frame.top + 2 * cornerRadius),
180, 90, false, paint); // 画弧
canvas.drawLine(frame.left + cornerRadius, frame.top, frame.left + cornerLength, frame.top, paint); // 水平线
canvas.drawLine(frame.left, frame.top + cornerRadius, frame.left, frame.top + cornerLength, paint); // 垂直线
// 右上角
canvas.drawArc(new RectF(frame.right - 2 * cornerRadius, frame.top, frame.right, frame.top + 2 * cornerRadius),
270, 90, false, paint); // 画弧
canvas.drawLine(frame.right - cornerRadius, frame.top, frame.right - cornerLength, frame.top, paint); // 水平线
canvas.drawLine(frame.right, frame.top + cornerRadius, frame.right, frame.top + cornerLength, paint); // 垂直线
// 左下角
canvas.drawArc(new RectF(frame.left, frame.bottom - 2 * cornerRadius, frame.left + 2 * cornerRadius, frame.bottom),
90, 90, false, paint); // 画弧
canvas.drawLine(frame.left + cornerRadius, frame.bottom, frame.left + cornerLength, frame.bottom, paint); // 水平线
canvas.drawLine(frame.left, frame.bottom - cornerRadius, frame.left, frame.bottom - cornerLength, paint); // 垂直线
// 右下角
canvas.drawArc(new RectF(frame.right - 2 * cornerRadius, frame.bottom - 2 * cornerRadius, frame.right, frame.bottom),
0, 90, false, paint); // 画弧
canvas.drawLine(frame.right - cornerRadius, frame.bottom, frame.right - cornerLength, frame.bottom, paint); // 水平线
canvas.drawLine(frame.right, frame.bottom - cornerRadius, frame.right, frame.bottom - cornerLength, paint); // 垂直线
// 重置画笔状态
paint.setStyle(originalStyle);
paint.setStrokeWidth(originalStrokeWidth);
paint.setColor(originalColor);
paint.setStrokeCap(originalCap);
}
/**
* 绘制模糊区域
*/
private void drawExterior(Canvas canvas, Rect frame, int width, int height) {
if (maskColor != 0) {
// 绘制整个模糊区域
paint.setColor(maskColor);
canvas.drawRect(0, 0, width, height, paint);
// 设置混合模式为清除
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
// 绘制圆角矩形的取景区域
float cornerRadius = UtilKt.dp2Px(12);
canvas.drawRoundRect(
new RectF(frame.left, frame.top, frame.right, frame.bottom),
cornerRadius, cornerRadius, paint
);
// 清除混合模式
paint.setXfermode(null);
}
}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

