2

I develop app where I want to take photo only on the middle square but by keeping the preview on almost the whole screen enter image description herelike in this picture. However, the imageproxy, after a cropping, does not look like the previous image, the width and height are bigger.enter image description here

I notice that what I see with my app and with the device photo app is a bit different, my app seems to zoom a little.

What I've already try:

  • setViewPort with the middle view size
  • setTargetAspectRatio(AspectRatio.RATIO_4_3) to both ImageCapture and Preview
  • add a TextureView or SurfaceView or even another Preview in replacement of the middle view. That was good but I lost the transparency
  • one of the best solution was to add app:layout_constraintDimensionRatio="3:4" to the xml layout of the preview. But again I lost the transparency (the preview height was 4/3 higher than the width, and above and below, I had white banners.

So why the preview is different of the device camera's one ? Do you know a solution to set the preview on the whole screen but keep only a square center image ?

Turvy
  • 882
  • 1
  • 8
  • 23
  • 1
    Looks like the preview screen is 16:9 and the camera then takes 4:3 images. Try `scaleType="fitCenter"` for your preview TextureView and limit the width of the view to the width of the screen. – GenError Oct 05 '21 at 17:32
  • @GenError, actually it works like `app:layout_constraintDimensionRatio="3:4"` to the xml, the area of transparency is cropped – Turvy Oct 06 '21 at 12:48
  • you can try solution in post https://stackoverflow.com/questions/59242315/how-to-crop-image-rectangle-in-camera-preview-on-camerax – MKD Oct 21 '21 at 09:28

0 Answers0