Preview View stretched on SM-G570M

146 views
Skip to first unread message

Jonathan Beutke

unread,
Nov 10, 2020, 12:10:56 PM11/10/20
to Android CameraX Discussion Group

Hello!.

The previewView on this device (SM-G570M) is stretched.
I've tried a lot of things, but I can't fix it.


Screenshot_20201110-134906.jpg

Library Version: (same issue in all versions)
androidx.camera:camera-camera2:1.0.0-beta11
androidx.camera:camera-view:1.0.0-alpha18


Source code

Aspect ratio:
        private fun aspectRatio(width: Int, height: Int): Int {
            val previewRatio = max(width, height).toDouble() / min(width, height)
            if (abs(previewRatio - RATIO_4_3_VALUE) <= abs(previewRatio - RATIO_16_9_VALUE)) {
                return AspectRatio.RATIO_4_3
            }
            return AspectRatio.RATIO_16_9
        }

Preview Builder:
        val screenAspectRatio = aspectRatio(Utils.getDisplayWidth(applicationContext), Utils.getDisplayHeight(applicationContext))
        
        imagePreview = Preview.Builder().apply {
            setTargetAspectRatio(screenAspectRatio)
            setTargetRotation(preview_view.display.rotation)
        }.build()
        
        
        preview_view.scaleType = PreviewView.ScaleType.FILL_CENTER
        
        imagePreview.setSurfaceProvider(preview_view.surfaceProvider)



Thanks in advance!

Xi Zhang (张熹)

unread,
Nov 10, 2020, 12:42:18 PM11/10/20
to Jonathan Beutke, Android CameraX Discussion Group
Could you try setting the target aspect ratio to RATIO_16_9? e.g. for you aspectRatio() function to always return AspectRatio.RATIO_16_9.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/d4b4e471-27aa-4721-9639-68ec181404a4n%40android.com.

Jonathan Beutke

unread,
Nov 10, 2020, 1:06:43 PM11/10/20
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group, Jonathan Beutke
Hi! Thanks for your reply.
With RATIO_16_9 I still have the same problem

Jonathan Beutke

unread,
Mar 11, 2021, 3:40:57 PMMar 11
to Android CameraX Discussion Group, Jonathan Beutke, Xi Zhang, Android CameraX Discussion Group

Hi,
I still can't solve this issue, even with the latest version of camera-view. 
It only occurs on the SM-G570M device.

I need to know if this bug is tracked or will I have to code everything again with camera2.  :(

Thanks!

Xi Zhang (张熹)

unread,
Mar 11, 2021, 7:53:53 PMMar 11
to Jonathan Beutke, Android CameraX Discussion Group
Sorry for the late reply. Probably a similar issue to https://issuetracker.google.com/issues/180121821 If that's the case, camera2 should be the same. Please let me know if somehow camera2 works for you.

As for fix, we can apply a similar device specific workaround for the issue. If it's urgent, you can try to workaround it yourself. Basically you need to manually apply an additional transform to PreviewView for that specific device. e.g. setScaleY(1.33f).


Xi Zhang

unread,
Mar 18, 2021, 12:42:26 PMMar 18
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group, jonatha...@gmail.com

I am not able to repro the issue with SM-G570M. Could you try if the CameraXBasic app works? https://github.com/android/camera-samples/tree/master/CameraXBasic

And could you try removing the `setTargetAspectRatio(screenAspectRatio)` line from your code?

Jonathan Beutke

unread,
Mar 18, 2021, 12:57:22 PMMar 18
to Xi Zhang, Android CameraX Discussion Group
Hi!

I have tried cameraXBasic and other apps on the Play Store that use cameraX and I see the same problem.
Removing setTargetAspectRatio(screenAspectRatio), i get the same issue.

Adding setScaleY(1.33f) in the preview solves the problem, but drawing over preview view results in wrong coordinates :(

Xi Zhang (张熹)

unread,
Mar 18, 2021, 5:37:19 PMMar 18
to Jonathan Beutke, Android CameraX Discussion Group
What is your Android version? Mine is 6.0.1, later upgraded to 7.0 but still couldn't reproduce it. Also, could you try setting the PreviewView to COMPATIBLE mode?

Jonathan Beutke

unread,
Mar 18, 2021, 6:31:06 PMMar 18
to Xi Zhang (张熹), Android CameraX Discussion Group
With Compatible Mode is the same.
Android 8.0.0




--
Enviado desde mi iPhone

Xi Zhang (张熹)

unread,
Mar 18, 2021, 7:31:21 PMMar 18
to Jonathan Beutke, Android CameraX Discussion Group
I can reproduce the issue after upgrading to 8.0.0.  I will look for a solution.

Jonathan Beutke

unread,
Mar 20, 2021, 11:03:49 AMMar 20
to Xi Zhang (张熹), Android CameraX Discussion Group

Ok, Thank you!

Xi Zhang (张熹)

unread,
Mar 26, 2021, 9:20:29 PMMar 26
to Jonathan Beutke, Android CameraX Discussion Group
The issue is fixed and it will go out with the next release. See: https://android-review.googlesource.com/c/platform/frameworks/support/+/1647928

As for the coordinates transform are off, we are currently working on an API that will take care of the transformation. Please stay tuned.
Reply all
Reply to author
Forward
0 new messages