Zoom Control in Camera is not working in Android

夙愿已清 提交于 2019-12-24 21:22:29

问题


I am working on Custom Camera using Surface view in my application, also recording Video with screen Capture.

I am looking to implement Zoom Control in my Camera Code but not getting success.

Getting this log while Zooming:

E/Adreno200-ES20(12756): <qgl2DrvAPI_glBufferSubData:709>: GL_INVALID_OPERATION

I am using below code:

/** * setZoomControl * @param params */

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

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

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

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

        zoomControls.setOnZoomOutClickListener(new OnClickListener() {
            public void onClick(View v) {
                int currentZoomLevel = 0;
                if (currentZoomLevel > 0) {
                    currentZoomLevel--;
                    camera.startSmoothZoom(currentZoomLevel);
                }
            }
        });
    } else
        zoomControls.setVisibility(View.GONE);
}

Please suggest me whats happening in my code.


回答1:


You can use this code

if (params.isZoomSupported()) {
        final int 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++;
                    //mCamera.startSmoothZoom(currentZoomLevel);
                    params.setZoom(currentZoomLevel);
                    mCamera.setParameters(params);
                }
            }
        });

        zoomControls.setOnZoomOutClickListener(new OnClickListener(){
            public void onClick(View v){
                if(currentZoomLevel > 0){
                    currentZoomLevel--;
                    params.setZoom(currentZoomLevel);
                    mCamera.setParameters(params);
                }
            }
        });    
    }
    else
        zoomControls.setVisibility(View.GONE);


来源:https://stackoverflow.com/questions/18270222/zoom-control-in-camera-is-not-working-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!