T
T
Thymomenos Gata2018-07-10 15:58:19
Android
Thymomenos Gata, 2018-07-10 15:58:19

How to keep image orientation after taking a snapshot?

People,
help I create my own camera, everything works, except for one, when creating a picture - it is saved in reverse orientation, i.e. with vertical - a horizontal image is obtained, and with horizontal - a vertical one. Who knows how it is treated, help, I have already tried all the methods from the network, it does not help:
here is the part of the code that was supposed to solve the orientation problem:

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void setupCamera(String cameraId) {
        CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        try {
            CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
            StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            //TODO ORIENTATION OF PICTURES
            iCaptureRequestBuilder.addTarget(iImageReader.getSurface());
            iCaptureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION, getJpegOrientation(cameraCharacteristics));

            Size largestImageSize = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new Comparator<Size>() {
                @Override
                public int compare(Size lhs, Size rhs) {
                    return Long.signum(lhs.getWidth() * lhs.getHeight() - rhs.getWidth() * rhs.getHeight());
                }
            });

            iImageReader = ImageReader.newInstance(largestImageSize.getWidth(), largestImageSize.getHeight(), ImageFormat.JPEG, 1);
            iImageReader.setOnImageAvailableListener(iOnImageAvailableListener, iBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private int getJpegOrientation(CameraCharacteristics c) {
        int deviceOrientation = this.getWindowManager().getDefaultDisplay().getRotation();
        int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
        int surfaceRotation = ORIENTATIONS.get(deviceOrientation);
        int jpegOrientation = (surfaceRotation + sensorOrientation + 270) % 360;
        return jpegOrientation;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question