01
02
03
04
05
06
|
if(width < height) {
Log.i(TAG,"Display reports portrait orientation; assuming this is incorrect");
inttemp = width;
width = height;
height = temp;
}
|
01
|
camera.setDisplayOrientation(90);
|
01
02
03
04
|
rect.left = rect.left * cameraResolution.x / screenResolution.x;
rect.right = rect.right * cameraResolution.x / screenResolution.x;
rect.top = rect.top * cameraResolution.y / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
|
01
02
03
04
|
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
|
01
02
03
04
05
06
07
08
09
|
byte[] rotatedData =newbyte[data.length];
for(inty =0; y < height; y++) {
for(intx =0; x < width; x++)
rotatedData[x * height + height - y -1] = data[x + y * width];
}
inttmp = width;
width = height;
height = tmp;
data = rotatedData;
|
01
02
03
04
05
06
07
|
Point screenResolutionForCamera =newPoint();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if(screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
|
01
02
|
intwidth = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
intheight = findDesiredDimensionInRange(screenResolution.y,MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
|
01
02
03
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
intwidth = (int) (metrics.widthPixels *0.6);
intheight = (int) (width *0.9);
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
// 画出四个角
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);
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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;
}
|
此处采用了两种线条样式,一种是渐变线条,还有一种是类似微信的图片扫描线。
另外,扫描成功后的手机震动和提示音在BeepManager中修改,里面我额外放了两种提示音文件