9

zxingのキャプチャ画面(カメラ画面)にカスタムボーダーを入れたい。これにはどのような変更を加える必要がありますか? この効果を得るには、どのアクティビティとレイアウトを変更する必要がありますか?

4

4 に答える 4

12

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

ViewfinderViewfindonDrawメソッドで。「走査矩形」を描くコアです。必要に応じて変更できます。

実際に長方形を描画するコードは、次の場所にあります

// 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);
于 2011-05-14T21:49:14.053 に答える
5

この質問にはすでに答えがあります。しかし、誰かがキャプチャ画面の周りに境界線を描く方法が必要な場合は、ここにコードがあります. inazarukの答えは正しいです。私の答えは、その延長にすぎません。

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

ここに画像の説明を入力

于 2018-05-27T20:09:49.170 に答える
3

これは、SOの他の数人がそれを行った方法です。

こちらもご覧ください。

最後に、これを使用ます。

于 2011-05-10T15:50:54.043 に答える