基本信息
源码名称:二维码扫描(仿微信扫描界面)
源码大小:1.29M
文件格式:.zip
开发语言:Java
更新时间:2016-02-28
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍

简单的扫码Demo

@Override
public void onDraw(Canvas canvas) {
if (cameraManager == null) {
return;
}

Rect frame = cameraManager.getFramingRect();
if (frame == null) {
return;
}

int width = canvas.getWidth();
int height = canvas.getHeight();

// 画扫描框外部的暗色背景
// 设置蒙板颜色
paint.setColor(resultBitmap != null ? resultColor : maskColor);
// 头部
canvas.drawRect(0, 0, width, frame.top, paint);
// 左边
canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint);
// 右边
canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint);
// 底部
canvas.drawRect(0, frame.bottom, width, height, paint);

if (resultBitmap != null) {
// 在扫描框中画出预览图
paint.setAlpha(CURRENT_POINT_OPACITY);
canvas.drawBitmap(resultBitmap, null, frame, paint);
} else {
// 画出四个角
paint.setColor(getResources().getColor(R.color.green));
// // 左上角
// canvas.drawRect(frame.left, frame.top, frame.left 15,
// frame.top 5, paint);
// canvas.drawRect(frame.left, frame.top, frame.left 5,
// frame.top 15, paint);
// // 右上角
// canvas.drawRect(frame.right - 15, frame.top, frame.right,
// frame.top 5, paint);
// canvas.drawRect(frame.right - 5, frame.top, frame.right,
// frame.top 15, paint);
// // 左下角
// canvas.drawRect(frame.left, frame.bottom - 5, frame.left 15,
// frame.bottom, paint);
// canvas.drawRect(frame.left, frame.bottom - 15, frame.left 5,
// frame.bottom, paint);
// // 右下角
// canvas.drawRect(frame.right - 15, frame.bottom - 5, frame.right,
// frame.bottom, paint);
// canvas.drawRect(frame.right - 5, frame.bottom - 15, frame.right,
// frame.bottom, paint);

float v_width = (frame.right-frame.left)/15;
float v_height = (frame.right-frame.left)/45;

paint.setColor(getResources().getColor(R.color.green));
// 左上角
canvas.drawRect(frame.left, frame.top, frame.left v_width,
frame.top v_height, paint);
canvas.drawRect(frame.left, frame.top, frame.left v_height, frame.top
v_width, paint);
// 右上角
canvas.drawRect(frame.right - v_width, frame.top, frame.right,
frame.top v_height, paint);
canvas.drawRect(frame.right - v_height, frame.top, frame.right, frame.top
v_width, paint);
// 左下角
canvas.drawRect(frame.left, frame.bottom - v_height, frame.left v_width,
frame.bottom, paint);
canvas.drawRect(frame.left, frame.bottom - v_width, frame.left v_height,
frame.bottom, paint);
// 右下角
canvas.drawRect(frame.right - v_width, frame.bottom - v_height,
frame.right, frame.bottom, paint);
canvas.drawRect(frame.right - v_height, frame.bottom - v_width,
frame.right, frame.bottom, paint);

// 在扫描框中画出模拟扫描的线条
// 设置扫描线条颜色为绿色
paint.setColor(getResources().getColor(R.color.green));
// 设置绿色线条的透明值
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
// 透明度变化
scannerAlpha = (scannerAlpha 1) % SCANNER_ALPHA.length;

// 画出固定在中部的线条
// int middle = frame.height() / 2 frame.top;
// canvas.drawRect(frame.left 2, middle - 1, frame.right - 1,
// middle 2, paint);

// 将扫描线修改为上下走的线
if ((i = 5) < frame.bottom - frame.top) {
/* 以下为用渐变线条作为扫描线 */
// 渐变图为矩形
// mDrawable.setShape(GradientDrawable.RECTANGLE);
// 渐变图为线型
// mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
// 线型矩形的四个圆角半径
// mDrawable
// .setCornerRadii(new float[] { 8, 8, 8, 8, 8, 8, 8, 8 });
// 位置边界
// mRect.set(frame.left 10, frame.top i, frame.right - 10,
// frame.top 1 i);
// 设置渐变图填充边界
// mDrawable.setBounds(mRect);
// 画出渐变线条
// mDrawable.draw(canvas);

/* 以下为图片作为扫描线 */
mRect.set(frame.left - 6, frame.top i - 6, frame.right 6,
frame.top 6 i);
lineDrawable.setBounds(mRect);
lineDrawable.draw(canvas);

// 刷新
invalidate();
} else {
i = 0;
}

// 重复执行扫描框区域绘制(画四个角及扫描线)
postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top,
frame.right, frame.bottom);
}
}