android Camera 设置焦距

android Camera 设置焦距

1、添加Camera权限

2、判断是否支持变焦

www.zeeklog.com  - android Camera 设置焦距
public boolean isSupportZoom()
    {
        boolean isSuppport = true;
        if (mCamera.getParameters().isSmoothZoomSupported())
        {
            isSuppport = false;
        }
        return isSuppport;
    }
www.zeeklog.com  - android Camera 设置焦距

3、修改焦距

www.zeeklog.com  - android Camera 设置焦距
public void setZoom()
    {
        if (mIsSupportZoom)
        {
            try
            {
                Parameters params = mCamera.getParameters();
                final int MAX = params.getMaxZoom();
           if(MAX==0)return;

                int zoomValue = params.getZoom();
                Trace.Log("-----------------MAX:"+MAX+"   params : "+zoomValue);
                zoomValue += 5;
                params.setZoom(zoomValue);
                mCamera.setParameters(params);
                Trace.Log("Is support Zoom " + params.isZoomSupported());
            }
            catch (Exception e)
            {
                Trace.Log("--------exception zoom");
                e.printStackTrace();
            }
        }
        else
        {
            Trace.Log("--------the phone not support zoom");
        }
    }