如何调和相机预览大小和图片大小之间的纵横比差异 [英] How to reconcile difference in aspect ratio between camera preview size and picture size

查看:11
本文介绍了如何调和相机预览大小和图片大小之间的纵横比差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相机应用程序,它根据我的布局特征(主要是纵横比)选择预览尺寸,然后根据其他限制(最小尺寸)选择图片尺寸.这通常会导致图片的纵横比与预览不同.

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.

推荐答案

经过一些额外的尝试和错误,我得出了以下初步结论:

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

  1. Camera.Parameters.getSupportedPictureSizes提供的最大图片尺寸代表相机的原生分辨率.

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

其他图片尺寸的内容,以及 Camera.Parameters.getSupportedPreviewSizes 提供的预览尺寸,将在按 所述放大时匹配原生内容Matrix.ScaleToFit.CENTER.(基本上从中心缩放,直到上/下或左/右达到原始分辨率的边界.如果纵横比不匹配,裁剪发生在未达到原始分辨率边界的维度中

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

因此,鉴于此,我的解决方案是首先将预览选择矩形缩放到本机相机图片大小.然后,既然我知道原生分辨率的哪个区域包含我想要的内容,我可以执行类似的操作,然后将原生分辨率上的矩形缩放为每个 Camera.Parameters.setPictureSize 实际捕获的较小图片.

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.

这篇关于如何调和相机预览大小和图片大小之间的纵横比差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆