Android Question CameraEx - Preview in full screen and aspect ratio

NJDude

Expert
Licensed User
I've seen some code posted about keeping the aspect ratio of the preview panel using the CameraEx class, all that is fine, but, what I'm trying to achieve is to have the same effect in FULL SCREEN just like the native camera app and I cannot find a solution, it looks "stretched" and distorted, let me reiterate, I don't need a panel centered on the screen but FULL screen.

Any clues will be appreciated.

Thanks
 

JordiCP

Well-Known Member
Licensed User
From all the preview sizes that the camera accepts, get the one that has the same aspect ratio (W/H) as your screen. If there is more than one, then choose based on
maximum or minimum size (W*H) criteria.

(edited)
If there isn't any preview aspect ratio which exactly matches your screen aspect ratio, then choose the closest one and make the panel slightly larger on one of its sides so that it matches the camera aspect ratio. A small portion of it will be off-screen , but it will not be noticeable
 

NJDude

Expert
Licensed User
That solution doesn't really work, when you snap a picture this will look different to what you see on the preview. But thanks for the reply.
 

JordiCP

Well-Known Member
Licensed User
Are you sure? I have used it a lot...
Of course you must choose a picture format (not only preview format) that matches the same aspect ratio criteria.
 

NJDude

Expert
Licensed User
No rush, take your time, I won't be able to test anything until I get home tonight.
 

JordiCP

Well-Known Member
Licensed User
I modified the camera example. It works as expected on my device. Modifications are the following

  • Example is now full-screen. So the preview panel expands to the whole screen
  • First it calculates the optimal preview and picture sizes based on your device aspect ratio. For this, it calls an inline Java function which opens, gets parameters, and closes the native camera.
  • Then, before initializing B4A camera, it asks you if you want to proceed with default parameters (as original example) or with the calculated ones. You should see the difference
  • All modifcations are under the tag #OPTIMAL to better track what is done. :)

(The example is assuming that your rear facing camera has index 0, and other things. Once it works, the procedure could be made more robust and ported to the CameraEx class. I had a modified version with similar changes but now I can't find it)
 

Attachments

NJDude

Expert
Licensed User
Cool, I appreciate your efforts, I will let you know the outcome after tonight.

Thanks
 
Top