简体   繁体   English

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

[英]How to make a resolution independent camera preview on android?

I'm making an android 1.6 app that uses phone's camera. 我正在制作一款使用手机相机的Android 1.6应用程序。

In order to do this app resolution independent, I need to set a compatible aspect ratio for previewing camera on a SurfaceLayout. 为了独立完成这个app分辨率,我需要设置一个兼容的宽高比来预览SurfaceLayout上的摄像头。 In 1.6 sdk there is no way to get supported sizes for the camera preview. 在1.6 sdk中,无法获得支持的相机预览尺寸。 It is possible to use a 4:3 or 3:2 aspect ratio and get no errors whith that? 可以使用4:3或3:2的宽高比,并且没有错误吗?

On the other hand, I need a way to make a xml layout that represents this Surfacelayout in this (unknown) aspect ratio in every resolution. 另一方面,我需要一种方法来制作一个xml布局,在每个分辨率中以此(未知)宽高比表示此Surfacelayout。 I assume that is not possible to change the SurfaceLayout size in runtime. 我假设无法在运行时更改SurfaceLayout大小。 Can I do it with "dp" units? 我可以用“dp”单位吗? The other way is making this layout programmatically? 另一种方法是以编程方式进行此布局?

There are some apps like Vignette or android camera application with some tricks to make something like that, like black bars (vignette) or fixed buttons bar, but I don't know how to do it in any kind of resolution. 有一些应用程序,如Vignette或Android相机应用程序,有一些技巧来制作类似的东西,如黑条(晕影)或固定按钮栏,但我不知道如何在任何类型的分辨率。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

In 1.6 sdk there is no way to get supported sizes for the camera preview. 在1.6 sdk中,无法获得支持的相机预览尺寸。

There is. 有。 You can get them in parsing the preview-size-values camera parameter. 您可以在解析preview-size-values相机参数时获取它们。

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);
        }
    }
}

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

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