0

I'm developing an app which has a SurfaceView with a camera. I want to take landscape images in both landscape and portrait modes. The preview is shown okay since I used camera.setDisplayOrientation(90); in my code.

However when I take the image, it is displayed rotated. I can rotate it again but it will become portrait as soon as it is done. Does anyone know how to take a landscape image from camera?

This is how I configured the camera parameters

     private void configure() {
        Camera.Parameters params = camera.getParameters();

        // Configure image format. RGB_565 is the most common format.
        List<Integer> formats = params.getSupportedPictureFormats();
        if (formats.contains(PixelFormat.RGB_565))
            params.setPictureFormat(PixelFormat.RGB_565);
        else
            params.setPictureFormat(PixelFormat.JPEG);

        // Choose the biggest picture size supported by the hardware
        /*List<Camera.Size> sizes = params.getSupportedPictureSizes();
        Camera.Size size = sizes.get(sizes.size()-1);
        params.setPictureSize(size.width, size.height);*/
        params.setPictureSize(Constants.IMAGE_WIDTH, Constants.IMAGE_HEIGHT);

        List<String> flashModes = params.getSupportedFlashModes();
        if (flashModes.size() > 0)
            params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);

        // Action mode take pictures of fast moving objects
        List<String> sceneModes = params.getSupportedSceneModes();
        if (sceneModes.contains(Camera.Parameters.SCENE_MODE_ACTION))
            params.setSceneMode(Camera.Parameters.SCENE_MODE_ACTION);
        else
            params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);

        // if you choose FOCUS_MODE_AUTO remember to call autoFocus() on
        // the Camera object before taking a picture 
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        camera.setParameters(params);
    }

And this is where I take the image

    private void takePicture()
    {
        configure();
        camera.autoFocus(new Camera.AutoFocusCallback() {

            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                camera.takePicture(shutterCallback, pictureCallback_RAW, pictureCallback_JPEG);
            }
        });
    }

This is where I save the image which is taken from the camera

     PictureCallback pictureCallback_JPEG = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {

            File storageDirectory = CameraHelper.getStorageDirectory();
            String fileName = CameraHelper.getStorageFileName();

            imagePath = storageDirectory.getPath()+File.separator+fileName;
            File output = new File(storageDirectory, fileName);
            try {
                FileOutputStream fos = new FileOutputStream(output);
                fos.write(data);
                fos.close();

                imageCapturedState=true;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

This is the camera preview when I take the picture

enter image description here

This is how it is displayed once it is saved (The image in the preview is rotated 90 degrees.)

enter image description here

So as you see, I can rotate the image, but it will become portrait once I have done it. How can I save a landscape image without ratating? Thank you!

A.M.N.Bandara
  • 1,490
  • 15
  • 32

0 Answers0