如何在android上制作分辨率独立的相机预览?

如何在android上制作分辨率独立的相机预览?,android,layout,camera,resolution,aspect-ratio,Android,Layout,Camera,Resolution,Aspect Ratio,我正在制作一款使用手机摄像头的android 1.6应用程序 为了使这个应用程序独立于分辨率,我需要为在SurfaceLayout上预览相机设置一个兼容的纵横比。在1.6 sdk中,无法获取相机预览支持的尺寸。可以使用4:3或3:2的长宽比,但不会产生任何错误 另一方面,我需要一种方法来制作一个xml布局,在每个分辨率中以这个(未知的)高宽比来表示这个Surfacelayout。我假设不可能在运行时更改SurfaceLayout大小。我可以用“dp”单位吗?另一种方法是以编程方式制作此布局 有一

我正在制作一款使用手机摄像头的android 1.6应用程序

为了使这个应用程序独立于分辨率,我需要为在SurfaceLayout上预览相机设置一个兼容的纵横比。在1.6 sdk中,无法获取相机预览支持的尺寸。可以使用4:3或3:2的长宽比,但不会产生任何错误

另一方面,我需要一种方法来制作一个xml布局,在每个分辨率中以这个(未知的)高宽比来表示这个Surfacelayout。我假设不可能在运行时更改SurfaceLayout大小。我可以用“dp”单位吗?另一种方法是以编程方式制作此布局

有一些像Vignette或android camera应用程序这样的应用程序,它们有一些技巧来制作类似的东西,比如黑条(Vignette)或固定按钮条,但我不知道如何以任何分辨率来实现

有什么想法吗

谢谢

在1.6 sdk中,无法获取相机预览支持的尺寸

有。您可以通过解析
预览大小值
摄影机参数获得这些值

String supportedSizesString = parameters.get("preview-size-values");
List<Size> supportedSizes = new ArrayList<Size>();
if (supportedSizesString != null && supportedSizesString.length() > 0) {
    StringSplitter ss = new TextUtils.SimpleStringSplitter(',');
    ss.setString(supportedSizesString);
    for (String supportedSize : ss) {
        String[] dimentions = supportedSize.split("x");
        if (dimentions.length > 1) {
            Size size = mCamera.new Size(Integer.parseInt(dimentions[0]),
            Integer.parseInt(dimentions[1]));
            supportedSizes.add(size);
        }
    }
}
String supportedSizeString=parameters.get(“预览大小值”);
List supportedSizes=new ArrayList();
if(supportedSizeString!=null&&supportedSizeString.length()>0){
StringSplitter ss=newtextutils.SimpleStringSplitter(',');
不锈钢固定管柱(支持的尺寸管柱);
用于(字符串支持大小:ss){
字符串[]维度=supportedSize.split(“x”);
如果(dimensions.length>1){
Size Size=mCamera.new Size(Integer.parseInt(维度[0]),
整数.parseInt(维度[1]);
支持的大小。添加(大小);
}
}
}