0

I build a "gallery" application. I have an issue with the orientation of images. I've created the images (camera) and believe that have set the orientation correctly. It can be shown in the built-in gallery and on my application on various devices.

Strangely on Sony Xperia, the ImageView of my application did not show correctly (built-in gallery showed correctly). Then I tried to set a rotation matrix for an ImageView and set the scaleType to matrix, yet it still did not work. I had to rotate the Bitmap itself before putting it in the ImageView.

So here is the question at last. How to check if an ImageView will work the orientation by itself, or not (and then the code should do what it has to do). I don't believe it is an Android version. My Sony Xperia is Android 4.4.4.

manfcas
  • 1,933
  • 7
  • 28
  • 47
Oren
  • 976
  • 9
  • 23

2 Answers2

0

You can rotate an bitmap of an imageview by using the below code

    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    // Decode Image using Bitmap factory.
    Bitmap bMap = BitmapFactory.decodeFile(uriimage.getPath(), bmOptions);  

    // Create object of new Matrix.
    Matrix matrix = new Matrix();

// set the rotation as per your requirement matrix.postRotate(90);

    // Create bitmap with new values.
    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(),
            bMap.getHeight(), matrix, true);

//now set the bitmap to imageview imageview.setBitmap(bmapRotate);

Hope it will help you

0

Prasad thank you.

Just after posting the question, I've found (in SO) the easy solution also for Sony Xperia.

Use: imageView.setRotation(orientation); Found it here: https://stackoverflow.com/a/14509371/1614089

Community
  • 1
  • 1
Oren
  • 976
  • 9
  • 23