QRCodeReaderView icon indicating copy to clipboard operation
QRCodeReaderView copied to clipboard

Camera preview was stretched when set width height of QRCodeReaderView

Open VAdaihiep opened this issue 8 years ago • 14 comments

I set width and height of QRCodeReaderView 300dp, the issue is: Camera preview is stretch, like fitXY scaleType in ImageView (If you need, i will capture screen)

Please help me to make camera preview keep aspect ratio when fix QRCodeReaderView width height. Thanks in advance.

VAdaihiep avatar May 10 '16 11:05 VAdaihiep

Please can you try with the latest version of the library 2.0.1?

dlazaro66 avatar Aug 20 '16 09:08 dlazaro66

I tried with latest version and is true that the camera preview is being stretched. Is there a way to fix this?

albertorusso90 avatar Aug 30 '16 09:08 albertorusso90

@albertorusso90 Yes, i had do like below:

  1. Create class QRCodeReaderViewWrapper extends ViewGroup, add a QRCodeReaderView inside this class.
  2. On @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom): Calculate child (qrcodereaderview width/height), then call getChildAt(0).layout(0, 0, childWidth, childHeight);

You can read this file i do with Android Vision Lib but similar with QRReaderView: https://github.com/VAdaihiep/FitCropAndroidVision/blob/master/app/src/main/java/vn/vadaihiep/fitcropandroidvision/camera/CameraSourcePreview.java

VAdaihiep avatar Aug 30 '16 09:08 VAdaihiep

I'm using the QRCodeReaderView in the upper half of a fragment. And i've got the same problem with the stretched preview. And I don't get @VAdaihiep comment... Did anyone solved this?

MontiDreamer avatar Sep 02 '16 12:09 MontiDreamer

Camera resolution is chosen based on View dimensions, so that's why the preview is stretched. One thing you can do while I try to find a solution is to partially hide a QRCodeReaderView with other views just to get that effect. For example, you can overlap your full-screen QRCodeReaderView with a half-size empty View or other components.

dlazaro66 avatar Sep 02 '16 13:09 dlazaro66

Thank you for this simple workaround :) I included this and for now, it's okay. But it would be great, if you could comment on this issue when you have found a solution.

MontiDreamer avatar Sep 05 '16 06:09 MontiDreamer

@dlazaro66 Unless I'm missing something, but putting a overlap view on top doesn't seem to solve the problem. If the QR code is at the bottom of the screen even the user doesn't see it in preview it still gets read by QRCodeReaderView. That's kinda confusing to users. How did you solve this problem?

yongsunCN avatar Oct 27 '16 15:10 yongsunCN

@yongsunCN I didn't solve it, It's just a workaround playing with the position of the views

dlazaro66 avatar Nov 07 '16 22:11 dlazaro66

@dlazaro66 Any update on this issue? My preview is also stretched when rotating the phone to landscape mode.

Glennmen avatar Feb 07 '18 09:02 Glennmen

any updates regarding the stretch issue?

mlostekk avatar Mar 30 '18 08:03 mlostekk

@mlostekk I have a demo but with Google Vision, not ZXing, you can try it here: https://github.com/VAdaihiep/FitCropAndroidVision

VAdaihiep avatar Apr 02 '18 03:04 VAdaihiep

I also met this issue but i change the code in the class of CameraConfigurationManager like this: if (cwNeededRotation == 90||cwNeededRotation==270) { //portrait resolution = new Point(width, height); } else { //0 180 resolution = new Point(height, width); } i solved my problem by this way (my QrCodeReaderView show normal ,my QrCodeReaderView is full_screen)even if i dont know why do this.

danfengfirst avatar Mar 07 '19 06:03 danfengfirst

@dlazaro66 I also met this issue but i change the code in the class of CameraConfigurationManager like this: if (cwNeededRotation == 90||cwNeededRotation==270) { //portrait resolution = new Point(width, height); } else { //0 180 resolution = new Point(height, width); } i solved my problem by this way (my QrCodeReaderView show normal ,my QrCodeReaderView is full_screen)even if i dont know why do this.

danfengfirst avatar Mar 07 '19 06:03 danfengfirst

as someone suggested somewhere else, you can easily fix it like this:

if (barcodeCapture.getView()!=null) {
           CameraSourcePreview cameraSourcePreview = barcodeCapture.getView().findViewById(R.id.preview);
           cameraSourcePreview.post(cameraSourcePreview::requestLayout);
       }

albert0m avatar Jul 02 '20 09:07 albert0m