我尝试在Samsung Note 8上将camera2应用到我的应用程序,然而,预览中的图像会变形 .

预览尺寸:2220x1080(比例18.5:9)

相机尺寸:1920x1080(比例16:9)

它似乎适合从1920x1080到2220x1080的图像大小

如何全屏预览和捕捉图像(2220x1080)?

public void createCameraPreviewSession() {

try {

SurfaceTexture texture = this.getSurfaceTexture();

assert texture != null;

texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());

Surface surface = new Surface(texture);

previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);

previewBuilder.addTarget(surface);

cameraDevice.createCaptureSession(Arrays.asList(surface, reader.getSurface()),

new CameraCaptureSession.StateCallback() {

@Override

public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {

if (null == cameraDevice) {

return;

}

previewSession = cameraCaptureSession;

thread = new HandlerThread("CameraPreview");

thread.start();

backgroundHandler = new Handler(thread.getLooper());

try {

previewBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

previewSession.setRepeatingRequest(previewBuilder.build(), null, backgroundHandler);

} catch (CameraAccessException e) {

e.printStackTrace();

}

}

@Override

public void onConfigureFailed(

@NonNull CameraCaptureSession cameraCaptureSession) {

}

}, null

);

} catch (CameraAccessException e) {

e.printStackTrace();

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐