Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reconcile difference in aspect ratio between camera preview size and picture size

I've got a camera app that selects a preview size based on characteristics of my layout (primarily aspect ratio) and then selects a picture size based on other constraints (minimum dimensions). This often results in a picture with a different aspect ratio than the preview.

This is not a problem in itself, but I need to map a rectangle on my preview to an equivalent rectangle on the picture so that I can extract the same area of the final photo that was visible in the preview when the photo was taken.

I understand that having different aspect ratios means that there will be portions of the rectangles that do not overlap, but I'm not working close enough to the edges that this should be an issue.

If it's not possible to know how the preview and photo map directly, is there perhaps a way to determine how they each map to the native camera? If I could programatically detect the native camera aspect ratio I might be able to determine the cropping scheme.

like image 793
goto10 Avatar asked Aug 08 '13 17:08

goto10


People also ask

Is aspect ratio the same as image size?

Put simply: Image size will determine how big or small the image is on a page. Aspect ratio is the proportional relationship between its width and height – so will determine its shape.

Does changing aspect ratio affect quality?

So, when you change the image aspect ratio, image resolution also changes. Nowadays, you are getting cameras with high resolutions like 18,20,50 megapixels. So, even if you crop the image for changing the aspect ratio, it will not affect your image quality.


1 Answers

After some additional trial and error, I've made the following tentative conclusions:

  1. The largest image size provided by Camera.Parameters.getSupportedPictureSizes represents the native resolution of the camera.

  2. The content of other picture sizes, as well as well as the preview sizes provided by Camera.Parameters.getSupportedPreviewSizes, will match the native content when scaled up as described for Matrix.ScaleToFit.CENTER. (basically scale from the center until either top/bottom or left/right hits the bounds of the native resolution. Cropping occurs in the dimension that doesn't reach the bounds of the native resolution if the aspect ratios don't match

So, given that, my solution was to first scale the preview selection rectangle to the native camera picture size. Then, now that I know which area of the native resolution contains the content I want, I can do a similar operation to then scale that rectangle on the native resolution to the smaller picture that was actually captured per Camera.Parameters.setPictureSize.

like image 191
goto10 Avatar answered Nov 15 '22 00:11

goto10