尝试使用camera2 api,需要一个功能,用户可以点击/重置以放大&缩小。
使用此代码进行缩放
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
float maxzoom = (characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM)) * 10;
Rect m = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
int minW = (int) (m.width() / maxzoom);
int minH = (int) (m.height() / maxzoom);
int difW = m.width() - minW;
int difH = m.height() - minH;
int cropW = 0, cropH = 0;
if (!touchFlagForZoom) {
cropW = difW / 100 * (int) 25;
cropH = difH / 100 * (int) 25;
touchFlagForZoom = true;
} else {
cropW = difW / 100 * (int) 0;
cropH = difH / 100 * (int) 0;
touchFlagForZoom = false;
}
cropW -= cropW & 3;
cropH -= cropH & 3;
Rect zoom = new Rect(cropW, cropH, m.width() - cropW, m.height() - cropH);
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoom);
try {
cameraCaptureSessions
.setRepeatingRequest(captureRequestBuilder.build(), null, null);
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (NullPointerException ex) {
ex.printStackTrace();
}
问题 它非常适合预览,但是当我在缩放后捕获图像时,它会得到未缩放的位图。
答案 0 :(得分:0)
您是否在静态捕获请求中设置了相同的裁剪区域?
裁剪区域是每帧设置,因此如果您在静止捕捉请求中使用默认裁剪区域,则会获得完整的FOV,而不是缩放。