我正在制作使用相机硬件的应用程序。我试图在相机视图中实现缩放缩放,但缩小功能不起作用,只是放大。这是我的代码: public boolean onTouchEvent(MotionEvent event){
Camera.Parameters params = mCamera.getParameters();
int action = event.getAction();
if (event.getPointerCount() > 1) {
if (action == MotionEvent.ACTION_POINTER_DOWN) {
float mDist = getFingerSpacing(event);
} else if (action == MotionEvent.ACTION_MOVE && params.isZoomSupported()) {
mCamera.cancelAutoFocus();
handleZoom(event, params);
}
} else {
if (action == MotionEvent.ACTION_UP) {
handleFocus(event, params);
}
}
return true;
}
@SuppressWarnings("deprecation")
private void handleZoom(MotionEvent event, Camera.Parameters params) {
int maxZoom = params.getMaxZoom();
int zoom = params.getZoom();
@SuppressWarnings("unused")
int currnetZoom = params.getZoom();
float newDist = getFingerSpacing(event);
float mDist = 0;
if (newDist > mDist) {
if (zoom < maxZoom)
zoom++;
} else if (newDist <= mDist) {
if (zoom >= 0)
zoom--;
}
mDist = newDist;
params.setZoom(zoom);
mCamera.setParameters(params);
}
@SuppressWarnings("deprecation")
public void handleFocus(MotionEvent event, Camera.Parameters params) {
int pointerId = event.getPointerId(0);
int pointerIndex = event.findPointerIndex(pointerId);
@SuppressWarnings("unused")
float x = event.getX(pointerIndex);
@SuppressWarnings("unused")
float y = event.getY(pointerIndex);
List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean b, Camera camera) {
}
});
}
}
/** Determine the space between the first two fingers */
@SuppressWarnings("deprecation")
private float getFingerSpacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
please I really need help. Thanks