dlazaro66 / QRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
1.9k stars 491 forks source link

Camera preview was stretched when set width height of QRCodeReaderView #47

Open VAdaihiep opened 8 years ago

VAdaihiep commented 8 years ago

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.

dlazaro66 commented 8 years ago

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

albertorusso90 commented 8 years ago

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

VAdaihiep commented 8 years ago

@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

MontiDreamer commented 8 years ago

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?

dlazaro66 commented 8 years ago

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.

MontiDreamer commented 8 years ago

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.

yongsunCN commented 7 years ago

@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?

dlazaro66 commented 7 years ago

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

Glennmen commented 6 years ago

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

mlostekk commented 6 years ago

any updates regarding the stretch issue?

VAdaihiep commented 6 years ago

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

danfengfirst commented 5 years ago

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 commented 5 years ago

@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.

albert0m commented 4 years ago

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