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.
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.
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.
After some additional trial and error, I've made the following tentative conclusions:
The largest image size provided by Camera.Parameters.getSupportedPictureSizes
represents the native resolution of the camera.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With