简体   繁体   English

Xamarin Android Camera2Api“ GetOutputSizes”始终返回最大640x480

[英]Xamarin Android Camera2Api “GetOutputSizes” always returns largest of 640x480

I'm very new to Android development and decided to approach it using Xamarin. 我对Android开发非常陌生,因此决定使用Xamarin进行开发。 I grabbed the Xamarin (C#) Camera2Api sample from Xamarin's website and got it to the point where I can load the camera preview, take a picture and persist that picture to disk. 我从Xamarin的网站上获取Xamarin(C#)Camera2Api示例,然后将其加载到可以加载相机预览,拍摄图片并将该图片保存到磁盘的位置。 However, when I look at the picture, it's always 640x480, which is fairly square. 但是,当我查看图片时,始终为640x480,这相当方形。

在此处输入图片说明

I notice in the Camera2Api project that this is set by grabbing the ScalerStreamConfigurationMap from the camera characteristics, and determining the largest supported size. 我注意到在Camera2Api项目中,这是通过从摄像机特征中获取ScalerStreamConfigurationMap并确定最大支持大小来设置的。 Here's the snippet: 这是代码段:

var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
if (map == null) {
    continue;
}

// For still image captures, we use the largest available size.
Size largest = (Size)Collections.Max(Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                                                     new CompareSizeByArea());

For whatever reason, the map.GetOutputSizes((int)ImageFormatType.Jpeg)) always returns a maximum of 640x480. 无论出于何种原因, map.GetOutputSizes((int)ImageFormatType.Jpeg)) 始终返回最大值640x480。

Can anyone shed some light as to why my emulator only supports such a square image, despite the actual camera preview taking up the full width and height of the screen? 尽管实际的相机预览占用了屏幕的整个宽度和高度,但是有人能说明我的模拟器为何仅支持这样的方形图像吗?

When using the Camera APIs it is important to remember that the capture image size is independent of the preview size.So even though your preview may be full width/height of screen this has no bearing on your capture image size. 使用Camera API时,请记住捕获图像的大小与预览大小无关,因此即使预览可能是屏幕的全宽/高度,这也与捕获图像的大小无关。

The reason 640x480 is being returned as your image size is because that is the largest size image that the "device" you are emulating supports, or its a limitation with the emulator itself. 返回640x480作为图像大小的原因是因为它是您正在仿真的“设备”支持的最大大小的图像,或者它是模拟器本身的限制。 If you were to run this test on a real device you would most likely see a different size image than what you are seeing on the emulator. 如果要在真实设备上运行此测试,则很可能会看到与模拟器上不同的尺寸图像。 Alternatively you could print a list of supported capture sizes with map.GetOutputSizes((int)ImageFormatType.Jpeg) and select a size from that list of a 4:3 aspect ratio at 640x480 is not what you want. 或者,您可以使用map.GetOutputSizes((int)ImageFormatType.Jpeg)打印支持的捕获大小列表,然后从该列表中选择4:3宽高比的大小,而不是640x480。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM