///自定义相机缩放崩溃(重新启动),三星移动android
void onZoom1() {
if (mStreamer == null || mVideoCaptureState != Streamer.CAPTURE_STATE.STARTED) {
return;
}
Log.d(TAG, "Set Camera.Parameters manually");
parameters = mStreamerGL.getCameraParameters();
if (parameters != null) {
if (parameters.isZoomSupported()) {
parameters.setZoom((int) mScaleFactor);
}
mStreamerGL.setCameraParameters(parameters);
}
}
//这就是我实现捏缩放的方法
public void onZoom2() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return;
}
if (mStreamer == null || mVideoCaptureState != Streamer.CAPTURE_STATE.STARTED) {
return;
}
Log.d(TAG, "Set Camera2 CaptureRequest manually");
final String cameraId = mStreamerGL.getActiveCameraId();
final android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
CaptureRequest.Builder builder = mStreamerGL.createCaptureRequest();
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
if (builder == null || characteristics == null) {
return;
}
builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO);
if (mMaxZoom > 1.0f) {
Rect sensor = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
int sensorCenterX = sensor.width() / 2;
int sensorCenterY = sensor.height() / 2;
int deltaX = (int) (0.5f * sensor.width() / mScaleFactor);
int deltaY = (int) (0.5f * sensor.height() / mScaleFactor);
Rect zoomRect = new Rect(
sensorCenterX - deltaX,
sensorCenterY - deltaY,
sensorCenterX + deltaX,
sensorCenterY + deltaY);
builder.set(CaptureRequest.SCALER_CROP_REGION, zoomRect);
}
mStreamerGL.setRepeatingRequest(builder);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
}
}
//我的ScaleListener
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
if (mMaxZoom < 0) {
findMaxZoom();
}
mScaleFactor *= scaleGestureDetector.getScaleFactor();
mScaleFactor = Math.max(0.5f, Math.min(mScaleFactor, mMaxZoom));
Log.d(TAG, "Max zoom=" + mMaxZoom + " zoom=" + (int) mScaleFactor);
if (mUseCamera2) {
onZoom2();
} else {
onZoom1();
}
return true;
}
}
//以上代码适用于三星移动以外的所有移动设备。我尝试变焦时,三星手机被冻结,然后重新启动。
有人可以帮我吗?预先感谢
答案 0 :(得分:-1)
忘记了所有的事情,只需使用以下语句即可。
Camera.Parameters params = camera.getParameters();
params.setZoom(zoom_value);
camera.setParameters(params);
通过上述代码,您可以仅通过设置值来对相机进行Zome,因此不需要任何复杂的Java代码。
需要更多帮助吗?
投票并询问查询。