Я использую API gcam camera2 и смог успешно сделать ЗЕЛЕНЫЙ прямоугольный оверлей, используя вид поверхности.Теперь задача состоит в том, чтобы сделать предварительный просмотр с помощью кнопки «out» только тогда, когда объект находится внутри прямоугольного наложения после касания четырех углов наложения.Пробовал много, но все равно безуспешно.Весь код взят из примера google camera2, поэтому представлена только та часть, где были внесены изменения.(https://github.com/googlesamples/android-Camera2Basic):
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
view.findViewById(R.id.picture).setOnClickListener(this);
view.findViewById(R.id.info).setOnClickListener(this);
mTextureView = view.findViewById(R.id.texture);
final SurfaceView surfaceView = view.findViewById(R.id.surfaceView);
surfaceView.setVisibility(View.VISIBLE);
surfaceView.setZOrderOnTop(true);
SurfaceHolder mHolder = surfaceView.getHolder();
mHolder.setFormat(PixelFormat.TRANSPARENT);
mHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder)
{
Canvas canvas = holder.lockCanvas();
if (canvas == null) {
Log.e(TAG, "Cannot draw onto the canvas as it's null");
} else {
int w = canvas.getWidth();
int h = canvas.getHeight();
int outerFillColor = 0x33000000;
float radius = 10.0f;
RectF rect = new RectF(100, 100, w - 100, h - 100);
// first create an off-screen bitmap and its canvas
Bitmap bitmap = null;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.O) {
bitmap = Bitmap.createBitmap(w, h,
Bitmap.Config.ARGB_8888);
}
Canvas auxCanvas = new Canvas(bitmap);
// then fill the bitmap with the desired outside color
Paint paint = new Paint(Paint.FAKE_BOLD_TEXT_FLAG);
paint.setColor(outerFillColor);
paint.setStyle(Paint.Style.FILL);
auxCanvas.drawPaint(paint);
// then punch a transparent hole in the shape of the rect
paint.setXfermode(new
PorterDuffXfermode(PorterDuff.Mode.CLEAR));
auxCanvas.drawRoundRect(rect, radius, radius, paint);
// then draw the white rect border (being sure to get rid of the xfer
mode!)
paint.setXfermode(null);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
auxCanvas.drawRoundRect(rect, radius, radius, paint);
// finally, draw the whole thing to the original canvas
canvas.drawBitmap(bitmap, 0, 0, paint);
holder.unlockCanvasAndPost(canvas);
}
}