我正在为Galaxy S7编写一个应用程序,该应用程序显示实时Camera2预览,在该预览中,我希望使用以下方法控制缩放级别:
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCropPreview);
cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);对于所需的不同作物/缩放,Rect zoomCropPreview被更改。由于S7支持8的最大数字变焦,其传感器阵列大小为4032x3024,因此我很难确定Rect值。我已经看过reprocess.html的指导,但我被困住了。
例如,zoomCropPreview =(0,4032,3024)和(0,504,378)-8倍变焦一样会产生罚款。但其他区域,如(250,250,504,378)或(1512,1134,1008,756)则不起作用,即使它们的边界在传感器阵列内。以下是基于https://inducesmile.com/android/android-camera2-api-example-tutorial/的代码的摄像机预览部分
protected void createCameraPreview() {
try {
SurfaceTexture texture = textureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
//The camera is already closed
if (null == cameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
//try to change zoom
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCropPreview);
cameraCaptureSessions = cameraCaptureSession;
updatePreview(); //update preview screen
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Toast.makeText(AndroidCameraApi.this, "Configuration change", Toast.LENGTH_SHORT).show();
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}如何确定scalar_crop_region的正确Rect值?
发布于 2017-07-17 17:47:46
如果您查看地域的文档,它会告诉您
作物区域的宽度和高度不能分别设置为小于地面( activeArraySize.width / android.scaler.availableMaxDigitalZoom )和地面( activeArraySize.height / android.scaler.availableMaxDigitalZoom )。
文档还指出,它将根据硬件和诸如此类的内容进行圆整--您想要计算您的弹出区域的高度和宽度。从这些项目中,您可以计算左上角和右下角。这些角落将提供您的裁剪区域的面积。
float cropW = activeArraySize.width() / zoomLevel;
float cropH = activeArraySize.height() / zoomLevel;
// now we calculate the corners
int top = activeArraySize.centerY() - (int) (cropH / 2f);
int left = activeArraySize.centerX() - (int) (cropW / 2f);
int right = activeArraySize.centerX() + (int) (cropW / 2f);
int bottom = activeArraySize.centerY() + (int) (cropH / 2f);记住,屏幕的左上角是0,0。把这个画出来,以便进一步澄清。
https://stackoverflow.com/questions/43020236
复制相似问题