GameSalutes
GameSalutes

Reputation: 1870

Android Camera.Parameters.getZoomRatios() only returns 1 value

I am trying to get all the zoom values supported for the camera and offer the user a slider to move between them. The problem is I only get one value back from Camera.Parameters.getZoomRatios(). I am testing on HTC Sensation device with Android 2.3.4 (gingerbread)

final Parameters parameters = camera.getParameters();

if(parameters.isZoomSupported()) {
    // get all the zoom levels
    final List<Integer> zooms = parameters.getZoomRatios();

zooms is always [100] This is also waht what I am getting back from parameters.getMaxZoom().

I've requested all relevant permissions in my android manifest and followed the instructions in the Camera API javadocs.

My native camera app on that device supports many zoom values. Any ideas on what may be the issue here?

Upvotes: 2

Views: 4603

Answers (1)

Daniel Smith
Daniel Smith

Reputation: 8579

Zoom ratios are probably not what you are looking for. Your camera can zoom from 0 to whatever is returned from getMaxZoom. Try calling setZoom on values from 0 to 100 (you say that is being returned from getMaxZoom), and see if that works.

Your slider could instead go from 0 to whatever is returned from getMaxZoom. As with many camera parameters on android, zoom ratios may not always be so trustworthy from every different vendor.

According to the documentation, the valid range for setZoom is 0 to getMaxZoom(). I have had mixed results with zoom working perfectly on all devices, but have just tested this on an HTC Sensation running 4.0.3. For getMaxZoom() I get 5 as the resulting int, and setting zoom from 0-5 works to zoom the camera. Your issue may stem from some issues the device may have had with Gingerbread, because when I print the zoomratios array I get the following:

[100, 114, 131, 151, 174, 200]

The zoom ratios array is meant to understand the factor by which each zoom level will zoom your image from a baseline of 1.0x zoom (multiplied by 100). In the above example a setting the zoom to 2 would give zoom to the third zoom ratio bucket: a 1.31x magnification. This also shows why the first value is 100 -- because the first zoom value of 0 is equivalent to a 1.0x zoom.

It seems as though zoom is totally wonky on your device if you are getting 100 returned from the max zoom query. I would recommend throwing a try-catch around your setParameters call if this is the case to guard for manufacturer error.

Upvotes: 2

Related Questions