I am setting an image on the imageview picked from the gallery(camera album). If the picked image has landscape orientation, it displays perfectly but if the image in in portrait mode(i.e the image was clicked in portrait mode) it is displaying the image with a 90 degree rotation. Now I am trying to find out the orientation just before setting on imageview, but all the images are giving same orientation and same width-height. Here is my code :
Uri selectedImage = intent.getData();
if (selectedImage != null) {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
int str = new ExifInterface(selectedImage.getPath()).getAttributeInt("Orientation", 1000);
Toast.makeText(this, "value:" + str, Toast.LENGTH_LONG).show();
Toast.makeText(this, "width:" + bitmap.getWidth() + "height:" + bitmap.getHeight(), Toast.LENGTH_LONG).show();
This work for me :
Here is a great solution I came across for this: >https://stackoverflow.com/a/34241250/8033090
One line solution:
or
This will autodetect rotation and place image in correct orientation
Picasso is a very powerful library for handling images in your app includes: Complex image transformations with minimal memory use. It can take a second to load but I just put some text behind the image view that says "Loading image" and when the image loads it covers the text.
This is also working for me:
Use
ExifInterface
for rotate image. Use this method for get correct value to be rotate captured image from camera.And put this code in Activity result method and get value to rotate image...
Hope this helps..
Another solution is to use the ExifInterface from support library: ExifInterface from support library