3

I have this function to add zoom control to my camera app. This function is called from surfaceChanged()

But on many of the devices pressing + / - for zoom out / in shows no effect. These devices support Zoom . Also the code is working on sony xperia , so the code must be correct.

Please help me to fix it. Is there anything more i need to do .

public void setZoomControl(Camera.Parameters params) {
    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.CAMERA_ZOOM_CONTROLS);

    if (params.isZoomSupported()) {
        maxZoomLevel = params.getMaxZoom();
        Log.i("max ZOOM ", "is " + maxZoomLevel);
        ;

        zoomControls.setIsZoomInEnabled(true);
        zoomControls.setIsZoomOutEnabled(true);

        zoomControls.setOnZoomInClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (currentZoomLevel < maxZoomLevel) {
                    currentZoomLevel++;
                    camera.startSmoothZoom(currentZoomLevel);
                }
            }
        });

        zoomControls.setOnZoomOutClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (currentZoomLevel > 0) {
                    currentZoomLevel--;
                    camera.startSmoothZoom(currentZoomLevel);
                }
            }
        });
    } else
        zoomControls.setVisibility(View.GONE);
}
png
  • 4,368
  • 7
  • 69
  • 118
  • 3
    According to documentation you should check against ``params.isSmoothZoomSupported()`` to see whether ``Camera.startSmoothZoom(..)`` is available. – harism Jan 14 '13 at 12:43
  • 1
    Yes, that was the issue . Smoothzoom was not supported. So instead of startSmoothZoom() , we have to call setZoom() and then camera.setparams. Please add your comment as answer, then i can accept it. Thank you – png Jan 14 '13 at 13:02
  • Harism plzz provide d full if it is working for customise camera. – Balwinder Singh Jun 27 '13 at 11:32
  • preetha plzz provide d full if it is working for customise camera. – Balwinder Singh Jun 27 '13 at 12:16
  • @preetha hi i also want to add zooming functionality in my app, created Custom Camera, but i have some small issues, will you help me? – Android Nov 28 '13 at 04:27
  • @preetha.. even I was also facing the same issue ... instead of SmoothZoom only Zoom was supported.. Thanks :) – androidDev May 13 '14 at 06:19

1 Answers1

1

I solved this problem.

Don't used startSmoothZoom() method

Camera.Parameters params = camera.getParameters();
params.setZoom(zoom_value);
camera.setParameters(params);
Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
Hantash Nadeem
  • 458
  • 6
  • 10