Android Question Camera2 example to landscape - preview image distortion

Cainsoft

Member
Licensed User
Longtime User
Hi,
I tried to use the camera2 example in landscape view. (#SupportedOrientations: landscape)
The preview image has been stretched and enlarged, but the photo is good. (see attachment)
I tried the following:
- changed cam.PreviewSize.Initialize(1920, 1080) -> cam.PreviewSize.Initialize(1080, 1920)
- created a landscape design variant

but these did not help.

I don't know, this is a bug or I'm doing something wrong.

Thanks in advance,
Attila
 

Attachments

  • Preview_landscape.jpg
    Preview_landscape.jpg
    67.7 KB · Views: 254
  • Final_photo_landscape.jpg
    Final_photo_landscape.jpg
    71.3 KB · Views: 253

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't change the preview size.

Change this method to:
B4X:
Private Sub ResizePreviewPanelBasedPreviewSize
    Dim pw = cam.PreviewSize.Width, ph = cam.PreviewSize.Height As Int
    Dim r As Float = Max(Root.Width / pw, Root.Height / ph)  'FILL_NO_DISTORTIONS (change to Min for FIT)
    Dim w As Int = pw * r
    Dim h As Int = ph * r
    pnlCamera.SetLayoutAnimated(0, Round(Root.Width / 2 - w / 2), Round(Root.Height / 2 - h / 2), Round(w), Round(h))
End Sub
 
Upvote 0

Cainsoft

Member
Licensed User
Longtime User
Don't change the preview size.

Change this method to:
B4X:
Private Sub ResizePreviewPanelBasedPreviewSize
    Dim pw = cam.PreviewSize.Width, ph = cam.PreviewSize.Height As Int
    Dim r As Float = Max(Root.Width / pw, Root.Height / ph)  'FILL_NO_DISTORTIONS (change to Min for FIT)
    Dim w As Int = pw * r
    Dim h As Int = ph * r
    pnlCamera.SetLayoutAnimated(0, Round(Root.Width / 2 - w / 2), Round(Root.Height / 2 - h / 2), Round(w), Round(h))
End Sub

It works, thank you Erel!
 
Upvote 0
Top