Android Question Camera preview BUG

Douglas Farias

Expert
Licensed User
Longtime User
hi all.
i need make a app with camera, and i m using the camex for this. ok its working fine, but on many devices the imagepreview of camera is crazy
I'm having flattened images
i know, i need to set the camEx.SetPreviewSize but how to set correct size for all devices? i dont understand this
i dont see any correct size for use
i m make a log with all previewsize, later i have try use all sizes and all sizes have the same bug
i dont undestand

i go upload 4 images here, 2 normal with moto g native camera and 2 images with s3 camex

thx to all
 

Attachments

  • 10581713_859788534051364_346528471_n.jpg
    10581713_859788534051364_346528471_n.jpg
    58.5 KB · Views: 123
  • 10748760_859788640718020_1765989736_n.jpg
    10748760_859788640718020_1765989736_n.jpg
    54.5 KB · Views: 135
  • 10799812_859788467384704_1199137295_n.jpg
    10799812_859788467384704_1199137295_n.jpg
    55.7 KB · Views: 132
  • 10805063_859788687384682_1736761549_n.jpg
    10805063_859788687384682_1736761549_n.jpg
    62.3 KB · Views: 114

Douglas Farias

Expert
Licensed User
Longtime User
Yes i m using but all preview sizes i have stretched image
look at my cup on this image, with s3 its very bug later look at normal cup image
how to fix this? i have tested on all previewsizes and all previewsize i have the same error on s3
 

Attachments

  • 10799812_859788467384704_1199137295_n.jpg
    10799812_859788467384704_1199137295_n.jpg
    55.7 KB · Views: 103
  • 10805063_859788687384682_1736761549_n.jpg
    10805063_859788687384682_1736761549_n.jpg
    62.3 KB · Views: 111
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
but how ?
for example when i get the previewsizes i cant set another value
only for example i get 400 x 400 and my panel is 700 x 400 (only example)
how can i set 400 x 400 on 700 x 400?
i cant use setpreviewsize 700 x 400 because this value dont exist, how can i make this can u give me a samples pls?
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
I'm going to offer my two cents. I hope it addresses the question in some way.

Like Erel said you need to adjust the size and aspect ratio of the panel to match the preview size. In addition to doing this I found that you also need to adjust the size of the surface that is a child view of the panel to match the panel. The surface is where the preview image is actually displayed.

I'm going to write some code off the top of my head. It will be conceptually accurate, but I'm sure it will have plenty of syntax and naming errors.

Suppose you are in the Camera_Ready routine, success=true. You want to adjust the preview image size. You already know 640x480 is a supported size.

camex.setPreviewSize(640, 480)

pnlCam.setLayout(Activity.Width - 480) / 2, (Activity.Height - 640) / 2, 480, 640) ' centers the panel on the screen and sets the size

Dim v as View = pnlCam.getview(0) ' Gets the surface view from the panel

v.setLayout(0, 0, 480, 640) ' makes the surface the same size as the panel

I didn't put this in a code block because it's similar to what I've used, but it's not tested.

Barry.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
thx
but i dont understand your calc here
B4X:
camEx.SetPreviewSize(1280,720)
paineltransparentcamera.setLayout((Activity.Width - 1280) / 2, (Activity.Height - 720) / 2, 1280, 720)
Dim v As View = paineltransparentcamera.getview(0)
v.setLayout(0, 0, 1280, 720)

this in my case is like your example , but it is very strange i dont understand the calc here =(
 

Attachments

  • Screenshot (10-27AM, nov 10, 2014).png
    Screenshot (10-27AM, nov 10, 2014).png
    447.5 KB · Views: 132
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
When I look at the picture, the black area seems to be the phone in portrait orientation (taller than wide). It looks to me like the preview image is wider than tall.

What happens if you swap the width and height in the setLayout commands or swap the width and height in the SetPreviewSize command?
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
i have fixed with comitparameters later
B4X:
        camEx.JpegQuality=90
        camEx.SetContinuousAutoFocus
        camEx.StartPreview
        camEx.SetPreviewSize(1280,720)
        paineltransparentcamera.setLayout(0,0,100%x,100%y)
        Dim v As View = paineltransparentcamera.getview(0)
        v.SetLayout(0,0,100%x,100%y)
        camEx.commitparameters
       
        Log(camEx.GetPreviewSize)
        Private lista As List
        lista.Initialize
        lista.AddAll(camEx.GetSupportedPreviewSizes)
        For i = 0 To lista.Size - 1
        Log(lista.Get(i))
        Next

but i need set the SetPreviewSize before use comitparameters

now is the question xD

how to get the values on this log

Installing file.
PackageAdded: package:click.fight.valow
Installing file.
PackageAdded: package:click.fight.valow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (notifica) Create **
** Service (notifica) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (telaprincipal) Create, isFirst = true **
** Activity (telaprincipal) Resume **
[Height=720, IsInitialized=false, Width=1280
]
[Height=720, IsInitialized=false, Width=1280
]
[Height=480, IsInitialized=false, Width=864
]
[Height=480, IsInitialized=false, Width=800
]
[Height=432, IsInitialized=false, Width=768
]
[Height=480, IsInitialized=false, Width=720
]
[Height=480, IsInitialized=false, Width=640
]
[Height=432, IsInitialized=false, Width=576
]
[Height=320, IsInitialized=false, Width=480
]
[Height=288, IsInitialized=false, Width=384
]
[Height=288, IsInitialized=false, Width=352
]
[Height=240, IsInitialized=false, Width=320
]
[Height=160, IsInitialized=false, Width=240
]
[Height=144, IsInitialized=false, Width=176
]
** Activity (telaprincipal) Pause, UserClosed = true **
Installing file.
PackageAdded: package:click.fight.valow

how to get the 1280x720 on this result?
[Height=720, IsInitialized=false, Width=1280
]
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
I've attached a test app based on Erel's CameraEX tutorial. I have three build configurations: CR1, CR2, and CR3

CR1 - closest to the CameraEX example with a full screen preview image.
CR2 - I change the size of the preview image panel and surface based on the reported preview image size.
CR3 - I swapped the reported preview image size height and width; using the swapped values to set the panel and surface size.

Quickly interpreting the results it seems as though the camera preview image size is reported assuming a landscape orientation, but when the phone is in portrait orientation the camera image is internally swapped so that it appears "upright".

In CR3, with the swapped width and height, the image looks correct when the phone is in portrait mode, but appears to have the wrong aspect ratio (image horizontally compressed) when the phone is in landscape orientation.

Barry.
 

Attachments

  • camera.zip
    9.9 KB · Views: 123
Upvote 0
Top