java 如何在android中获得支持的摄像机分辨率?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5934829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get supported video camera resolutions in android?
提问by jln646v
I am writing an app where I am allowing the user to capture video using the phones camera. I am using my own code to record the video as opposed to Androids built in camera app.
我正在编写一个应用程序,允许用户使用手机摄像头捕捉视频。我使用自己的代码来录制视频,而不是 Android 内置的相机应用程序。
Everything is working OK except I need to be able to access the list of supported camera resolutions so I can choose at runtime which one to use. I am looking for something like getSupportedPictureSizes()
but for video. Android 3.0 has this functionality but I am looking for something for 2.2.
一切正常,除了我需要能够访问支持的相机分辨率列表,以便我可以在运行时选择使用哪个。我正在寻找类似getSupportedPictureSizes()
但视频的东西。Android 3.0 具有此功能,但我正在寻找适用于 2.2 的功能。
As of right now I am using CamcorderProfile.QUALITY_HIGH / QUALITY_LOW
, but this only gives me two options and on the phones I have been testing on, the file sizes are at each extreme.(QUALITY_LOW is 216 kb/s and QUALITY_HIGH is > 3 MB/s)
截至目前,我正在使用CamcorderProfile.QUALITY_HIGH / QUALITY_LOW
,但这仅给了我两个选择,并且在我一直在测试的手机上,文件大小各不相同。(QUALITY_LOW 为 216 kb/s,QUALITY_HIGH 为 > 3 MB/s)
Any help would be greatly appreciated, Thank You!
任何帮助将不胜感激,谢谢!
回答by alxscms
Did you try to use the getSupportedVideoSizes()
methodfrom Camera.Parameters
class?
你尝试使用getSupportedVideoSizes()
方法的Camera.Parameters
类?
public List<Camera.Size> getSupportedVideoSizes()
This method returns a list of Size objects. It will return null
if the camera does not have separate preview and video output. The answer hereindicates that when this returns null
you may use the getSupportedPreviewSizes()
list.
此方法返回 Size 对象的列表。null
如果相机没有单独的预览和视频输出,它将返回。这里的答案表明,当它返回时,null
您可以使用该getSupportedPreviewSizes()
列表。
回答by jln646v
Ok I think I figured it out. It seems to work correctly on the phones I have been testing on.
好吧,我想我想通了。它似乎在我一直在测试的手机上正常工作。
List<Size> tmpList = camera.getParameters().getSupportedPreviewSizes();
final List<Size> sizeList = new Vector<Size>();
//compair the apsect ratio of the candidate sizes against the real ratio
Double aspectRatio = (Double.valueOf(getWindowManager().getDefaultDisplay().getHeight()) / getWindowManager().getDefaultDisplay().getWidth());
for(int i=0; i<tmpList.size(); i++){
Double tmpRatio = Double.valueOf(tmpList.get(i).height) / tmpList.get(i).width;
if(Math.abs(aspectRatio - tmpRatio) < .15){
sizeList.add(tmpList.get(i));
}
}