Camera's string parameters under Android API 7 (2.1 Eclair)
I am developping an application that uses the Camera
preview, take picture, and zoom functions.
I am trying to remain compatible with the Android API level 7 (2.1 Eclair), which does not implement Camera.Parameters.getMaxZoom()
, Camera.Parameters.setZoom()
, etc, so I have to use the String
parameters returned by the hardware. For example:
final String zoomSupportedString = parameters.get("zoom-supported"); // parameters is a Camera.Parameters
final boolean zoomSupported = (zoomSupportedString != null ? Boolean.parseBoolean(zoomSupportedString) : false);
if (zoomSupported) {
// Computes the min an max zoom levels for taking a picture:
final int minTake = parameters.getInt("taking-picture-zoom-min");
final int maxTake = parameters.getInt("taking-picture-zoom-max");
// etc.
}
But not all the devices use the same parameters, and I couldn't find any valid camera parameters list on the internet.
By checking the values returned by Camera.Parameter开发者_C百科s.flatten()
(see doc) on a HTC I could find "zoom-supported"
, "taking-picture-zoom-min"
, "taking-picture-zoom-max"
and "max-zoom"
. And surprisingly, I have found no "min-zoom"
.
But the parameter "taking-picture-zoom-min"
doesn't exist on Samsung Galaxy S, for example, and this leads null
to be returned and getInt()
to throw a NumberFormatException: 'null' cannot be parsed as an integer
.
Knowing that I am trying to remain compatible with Android-7, is there any better way to handle the zoom than using the string values returned by the hardware? And if so, is it possible to find somewhere a list of all the valid zoom parameters (or even a list by vendor)?
i know it's an old topic, but for those that are searching for Camera zoom... i had the same issue and now that i have 2 android devices which work differently, both had something in commmon.
Camera.Parameters.setZoom(int value)
didn't work on both of them, so i started testing. One device has "taking-picture-zoom-...;" but both devices have "zoom=...;" in the Camera.Parameters. On the device that has "taking-picture-zoom-...;", if i use Camera.Parameters.set("zoom", int value)
it would crash, while on the other it would work just fine. So, my solution is, when initializing the camera I store a boolean that holds true for Camera.Parameters.get("taking-picture-zoom")!=null
, and false otherwise. From that moment on, when setting zoom, just check the boolean and use the appropriate zoom-command... and that's it, works like a charm ! ofcourse, you could also just make a String hold the appropriate command and use that when setting zoom.
精彩评论