I have been trying to achieve something like this using android camera2.
I want a rectangle to load on top of my camera preview and once i press a button to capture the image then the image should be cropped within the rectangle preview. I have tried numerous solutions i could find but most of them are using the deprecated android hardware.camera and not camera2. The ones i could find with camera2 and textureview does not have the code for cropping. In the above image, I have put an overlay on my texture view using an image I made in photoshop. So how should i crop it just within the rectangle bounds?
Thanks.
2
Answers
To add the rectangle you can simply define an image in your xml layout file and position it in the centre of your preview.
Cropping uses the SCALAR_CROP_REGION:
Try this code, Its working for me
MainActivity.java
activiy_main.xml
ImageSurfaceView.java