我试图在我的相机记录应用程序中处理“s4 zoom”设备上的 ZoomIn/ZoomOut。因为它只支持常规缩放,即parameters.isZoomSupported()==true
, parameters.isSmoothZoomSupported()==false
,所以我parameters.setZoom(mZoomVal);
mCamera.setParameters(parameters);
照常使用。问题是缩放是生涩的、嘈杂的并且不平滑。有人知道如何像在三星相机应用程序中那样处理“s4 变焦”中的变焦速度吗?
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.v("onKeyDown keyCode="+keyCode+" event="+event.toString());
boolean handled = false;
switch(keyCode){
case KeyEvent.KEYCODE_FOCUS:
setAutoFocus();
handled = true;
break;
case KeyEvent.KEYCODE_CAMERA:
if(event.getRepeatCount() == 0){
if (isRec()) {
stopRec(1, 0);
} else {
startRec();
}
}
handled = true;
break;
case 256: //KeyEvent.KEYCODE_CAMERA_ZOOM_RING_MOVE:
handled = true;
break;
case 261: //KeyEvent.KEYCODE_CAMERA_ZOOM_RING_SPEED2
handled = true;
break;
case KeyEvent.KEYCODE_ZOOM_IN:
setZoomIn();
//AutoFocus();
handled = true;
break;
case KeyEvent.KEYCODE_ZOOM_OUT:
setZoomOut();
//AutoFocus();
handled = true;
break;
}
if(handled)
Log.v("onKeyDown HANDLED!");
else
return super.onKeyDown(keyCode, event);
return handled;
}
public int setZoomIn(){
if(mCamera == null){
return 0;
}
Parameters parameters = mCamera.getParameters();
List<Integer> zoom_list = parameters.getZoomRatios();
if(mZoomVal >= mZoomMax)
return zoom_list.get(mZoomMax);
/*
if(isAutoFocusing){
mCamera.cancelAutoFocus();
isAutoFocusing = false;
}*/
mZoomVal++;
isFocused = false;
parameters.setZoom(mZoomVal);
mCamera.setParameters(parameters);
mZoomVal = parameters.getZoom();
return zoom_list.get(mZoomVal);
}
public int setZoomOut(){
if(mCamera == null){
return 0;
}
Parameters parameters = mCamera.getParameters();
List<Integer> zoom_list = parameters.getZoomRatios();
if(mZoomVal <= 0)
return zoom_list.get(0);
/*
if(isAutoFocusing){
mCamera.cancelAutoFocus();
isAutoFocusing = false;
}*/
mZoomVal--;
isFocused = false;
parameters.setZoom(mZoomVal);
mCamera.setParameters(parameters);
mZoomVal = parameters.getZoom();
return zoom_list.get(mZoomVal);
}
public void setAutoFocus(){
if(mCamera == null){
return;
}
if(isFocused)
return;
if(isAutoFocusing){
mCamera.cancelAutoFocus();
isAutoFocusing = false;
}
isAutoFocusing = true;
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
Log.v("onAutoFocus success="+success);
isAutoFocusing = false;
isFocused = success;
}
});
}