看了Vurtexゞ. 文章《[Android實例] 條碼掃描二維碼掃描——ZXing android 源碼簡化 (附:支持中文) 》的基礎上對代碼進行了修改
1、增加了將代碼嵌套入自己工程后傳值的辦法(初學,如果有更好的方法也希望告訴我,先謝謝了)
2、掃碼界面進行了處理(初步實現了現有某些軟件的樣子,至於長的像誰就不說了)
//畫四個角的代碼
paint.setColor(frameColor); canvas.drawRect(15 + frame.left, 15 + frame.top,15 + (linewidht + frame.left), 15 + (50 + frame.top), paint); canvas.drawRect(15 + frame.left, 15 + frame.top,15 + (50 + frame.left), 15 + (linewidht + frame.top), paint); canvas.drawRect(-15 + ((0 - linewidht) + frame.right),15 + frame.top, -15 + (1 + frame.right),15 + (50 + frame.top), paint); canvas.drawRect(-15 + (-50 + frame.right), 15 + frame.top, -15+frame.right, 15 + (linewidht + frame.top), paint); canvas.drawRect(15 + frame.left, -15 + (-49 + frame.bottom),15 + (linewidht + frame.left), -15 + (1 + frame.bottom), paint); canvas.drawRect(15 + frame.left, -15+ ((0 - linewidht) + frame.bottom), 15 + (50 + frame.left), -15 + (1 + frame.bottom), paint); canvas.drawRect(-15 + ((0 - linewidht) + frame.right), -15+ (-49 + frame.bottom), -15 + (1 + frame.right), -15+ (1 + frame.bottom), paint); canvas.drawRect(-15 + (-50 + frame.right), -15+ ((0 - linewidht) + frame.bottom), -15 + frame.right, -15+ (linewidht - (linewidht - 1) + frame.bottom), paint);
linewidht變量控制四個角的寬度,下圖顯示的是設置為2時的效果
將ViewfinderView類中代碼中vmiddle hmiddle 變量定義下的這兩句替換可以變為小十字坐標
canvas.drawRect(hmiddle - 20, vmiddle - 1, hmiddle + 20,vmiddle + 2, paint); canvas.drawRect(hmiddle - 1, vmiddle - 20, hmiddle + 2,vmiddle + 20, paint);
代碼下載地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=225832&page=1&extra=#pid1997182
再貼一些經典的掃描界面
參考資料:
條碼掃描二維碼掃描——ZXing android 源碼簡化 (附:支持中文)