繁体   English   中英

缩放后在Camera2 Api中捕获图像

[英]Image Capturing in Camera2 Api after zooming

尝试使用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();
                }

问题它非常适合预览,但是当我在缩放后捕获图像时,它使我获得了未缩放的位图。

您是否仍在捕获请求中设置了相同的作物区域?

裁剪区域是每帧的设置,因此,如果在静止捕捉请求中使用默认的裁剪区域,则将获得完整的FOV,而不是缩放。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM