开发者

How to make a resolution independent camera preview on android?

开发者 https://www.devze.com 2023-01-31 07:54 出处:网络
I\'m making an android 1.6 app that uses phone\'s camera. In order to do this app resolution independent, I need to set a compatible aspect ratio for previewing camera on a SurfaceLayout. In 1.6 sdk

I'm making an android 1.6 app that uses phone's camera.

In order to do this app resolution independent, I need to set a compatible aspect ratio for previewing camera on a SurfaceLayout. In 1.6 sdk there is no way to get supported sizes for the camera preview. It is possible to use a 4:3 or 3:2 aspect ratio and get no errors whith that?

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. I assume that is not possible to change the SurfaceLayout size in runtim开发者_开发百科e. Can I do it with "dp" units? 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.

Any ideas?

Thanks!


In 1.6 sdk there is no way to get supported sizes for the camera preview.

There is. You can get them in parsing the preview-size-values camera parameter.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号