2013-08-16 54 views
1

我正在使用我的應用程序中的Surface視圖使用Custom Camera,並使用屏幕捕捉來錄製視頻。Camera中的變焦控制在Android中不起作用

我正在尋找在我的相機代碼中實現縮放控制,但沒有獲得成功。

獲取這個日誌變焦:

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

我使用下面的代碼:

/** * setZoomControl *參數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); 
} 

請建議我在我的代碼中發生了什麼。

回答

11

您可以使用此代碼

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);