0

I'm taking a picture, saving it as a file and displaying it as you can see the main imageView, then I use :

val filteredImage = bitmap.copy(Bitmap.Config.ARGB_8888,true)

I use this filteredImage variable to apply a filter on the image since it's now mutable.

the problem is: as you can see in the small images bellow the orientation changes and I searched a lot but I couldn't find any solution.

Image From the App

When I replace the main ImageView's bitmap with the copied one I got this :

The main <code>ImageView</code>'s bitmap orientation changed

Mohamed Hamdy
  • 137
  • 1
  • 12

1 Answers1

2

You original image may have Exif orientation data, which are lost on bitmap.copy().

@Override
public void onPictureTaken(CameraView cameraView, byte[] data) {
            // Find out if the picture needs rotating by looking at its Exif data
            ExifInterface exifInterface = new ExifInterface(new ByteArrayInputStream(data));
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
            int rotationDegrees = 0;
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotationDegrees = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotationDegrees = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotationDegrees = 270;
                    break;
            }
            // Create and rotate the bitmap by rotationDegrees
}

Look at this for details: https://stackoverflow.com/a/20480741/1159507

anber
  • 3,463
  • 6
  • 39
  • 68
  • I'm sorry I wrote it wrong. I need the bitmap to be mutable not immutable as I first wrote. the answer you suggested is pretty good and now I know how to keep the orientation, but the createBitmap used returns immutable bitmap which I can't apply my filter on. – Mohamed Hamdy Feb 28 '19 at 17:06