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

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

问题描述

我有一个摄像头应用程序,选择基于我的布局(主要是纵横比)的特性preVIEW大小,然后选择图片大小根据其他方面的限制(最小尺寸)。这通常导致具有比preVIEW一个不同的宽高比的画面。

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.

这本身不是一个问题,但我需要在我的preVIEW一个矩形映射到等效矩形上的图片,这样我可以提取的最后一张照片,这是在$ p可见的同一区域在拍摄照片时$ PVIEW。

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.

如果这是不可能知道如何preVIEW和照片直接映射,是有可能的方式来确定他们各自映射到本机摄像头?如果我能编程检测机摄像头长宽比我也许能确定种植计划。

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. 再$ P $提供的 Camera.Parameters.getSupportedPictureSizes 的最大图像尺寸psents相机的原始分辨率。

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

其他照片大小的内容,以及以及由 Camera.Parameters.getSupported previewSizes 提供的preVIEW大小,将匹配时所描述的 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

因此​​,鉴于这种情况,我的解决办法是,首先扩大了preVIEW选择矩形对本机相机图像尺寸。那么,现在我所知道的原始分辨率的哪个区域包含了我想要的内容,我可以做一个类似的操作,以按比例调整该矩形的原始分辨率较小的画面,实际上每个相机拍摄。 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.

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

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