How to make a resolution independent camera preview on android?
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);
}
}
}
精彩评论