Zxingバーコードリーダー:キャプチャ画面の周りにカスタムボーダーを作成する方法は?

StackOverflow https://stackoverflow.com/questions/5852059

質問

Zxingキャプチャ画面(カメラ画面)の周りにカスタムボーダーを配置したいと思います。これにどのような修正が必要ですか?この効果を得るためにどのアクティビティとレイアウトを変更する必要がありますか?

役に立ちましたか?

解決

レイアウトをまったく編集する必要はありません。

ViewfinderView 探す onDraw 方法。 「スキャン長方形」を描くのはコアです。あなたはあなたが望むようにそれを変更することができます。

実際に長方形を描くコードを見つけることができます ここ:

// 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。

実際、あなたはあなた自身のcolors.xmlファイルの色をオーバーライドすることができます。

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

この質問にはすでに答えがあります。しかし、誰かがキャプチャ画面の周りに境界線を描く方法が必要な場合は、ここにコードがあります。イナザルクの答えは正しいです。私の答えはそのための拡張機能です。

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top