getSupportedPictureSize()返回实际上并非Nexus4支持的值 [英] getSupportedPictureSize() returns a value which is not actually supported by Nexus4
问题描述
我纷纷伸出SurfaceView显示摄像头输入一个非常简单的摄像头应用程序。为了找到最佳的preVIEW大小为每个设备,我用这个样本code这是用在几乎所有的开源应用程序的摄像头我都看到:
I have extended a SurfaceView for displaying the camera feed for a very simple camera application. To find the optimal preview size for each device, I used this sample code which is used in almost all the open source camera apps I have seen:
List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
double minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.width - width) < minDiff) {
screenWidth = size.width;
screenHeight = size.height;
minDiff = Math.abs(size.width - width);
}
}
一切完美了这一点。
Everything works perfectly up to this point.
现在,由于应用程序的性质,我必须保持在内存中的两个位图在一个会话过程,并为简单起见(避免在测试过程中的内存问题)我用同样的$ C $下图片大小(取代了getSupported previewSizes()与getSupportedPictureSizes())。一切的伟大工程的大部分设备,虽然我已经决定选择最佳的图像大小为每个设备一些其他的方式。
Now, due to the nature of the application, I have to keep two bitmaps in the memory during the course of a session and for the sake of simplicity(avoiding memory issues during testing) I used the same code for the PICTURE SIZE(replaced the getSupportedPreviewSizes() with getSupportedPictureSizes()). Everything works great on most of the devices though I have to decide some other way to choose the optimum picture size for each device.
近日,在测试的的Nexus 4设备上,这上面的循环未能选择最佳的图像大小。经调查,我发现了getSupportedPictureSizes()函数返回一个值,也就是1280 * 960这是不实际的的Nexus 4摄像头的支持。那么,一个人如何解决这个问题?我的意思是,是不是这个功能应该只返回该设备的摄像头支持这些价值观?我相信还会有其他设备,我就不能来测试相同的问题。任何线索,如何这个问题应该得到解决?
Recently, while testing on an Nexus 4 device, this above loop failed in choosing the optimum picture size. Upon investigation, I found out that the getSupportedPictureSizes() functions returns a value i.e 1280*960 which is not actually supported by the Nexus 4 camera. So, how does one solve this issue? I mean, isn't this function supposed to ONLY return those values which the CAMERA of the device supports? I am sure there will be other devices with the same issue which I won't be able to test on. Any clues as to how this issue should be resolved?
更新: 发生了什么是它不接受任何错误,它返回被扭曲的图像错误的参数,我将努力让图片在这里。另外,还有一些不运行时异常。
UPDATE: Whats happening is that it accepts the wrong parameter without any error and the image that it returns is distorted, I will try to get a picture here as well. Also, there are no runtime exceptions.
推荐答案
我有一个LG清醒(型号为VS840 4G)同样的问题。基本上, getSupportedPictureSizes()
返回这些大小:
I have the same problem on an LG Lucid (model number VS840 4G). Basically, getSupportedPictureSizes()
returns these sizes:
Size Aspect Ratio
2560x1920 (1.3333333333333333)
3072x1728 (1.7777777777777777)
2048x1536 (1.3333333333333333)
2304x1296 (1.7777777777777777)
1536x864 (1.7777777777777777)
1280x960 (1.3333333333333333)
640x480 (1.3333333333333333)
如果我们称之为 setPictureSize()
与任何尺寸的1.7纵横比,摄像头硬件不引发错误,但它返回的是扭曲的图像:
If we call setPictureSize()
with any of the sizes with a 1.7 aspect ratio, the camera hardware throws no errors, but it returns an image that is distorted:
我尝试了一些技术,让摄像头驱动承认这个尺寸并没有真正的支持,包括检查 getPictureSize的结果()
和 getSupportedPictureFormats()
呼叫后 setParameters()
。我无法找到任何东西,一语道破了这种行为。
I tried a number of techniques to get the camera driver to admit this size was not really supported, including checking the result of getPictureSize()
and getSupportedPictureFormats()
after calling setParameters()
. I couldn't find anything that gave away this behavior.
要解决这个问题,我们现在模仿股票相机应用程序的行为:我们试图找到从 getSupportedPictureSizes一个preferred大小()
名单前回落至选择的最大(为计算由宽*高)。由于preferred尺寸都具有的高宽比1.333(4:3),此工作解决问题此设备上
To work around this, we now mimic the behavior of the stock Camera app: we attempt to find a "preferred" size from the getSupportedPictureSizes()
list before falling back to selecting the largest (as computed by width * height). Since the preferred sizes all have an aspect ratio of 1.333 (4:3), this works around the issue on this device.
请参阅相机的应用程序源代码<一href="https://android.googlesource.com/platform/packages/apps/Camera.git/+/master/src/com/android/camera/CameraSettings.java">where它将该值设置(111线)和<一href="https://android.googlesource.com/platform/packages/apps/Camera.git/+/android-cts-2.3_r12/res/values/arrays.xml">hard$c$cd确定其大小prefers (63行)的确切落实。
See the Camera app source where it sets the value (line 111) and the hardcoded sizes it prefers (line 63) for the exact implementation.
这篇关于getSupportedPictureSize()返回实际上并非Nexus4支持的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!