Rotates image from gallery

74 views Asked by At

I want load an image from gallery, everything is fine but the image is not displayed correctly, something rotates the image.

I use class ExifUtil:

    Uri selectedImage = imageReturnedIntent.getData();

                            try {

                                String imagePath = selectedImage.toString();
                                Bitmap myBitmap = decodeUri(selectedImage);

                                Bitmap orientation = ExifUtil.rotateBitmap(imagePath, myBitmap);
                                photoEdit.setImageBitmap(orientation); 

                            } catch (Exception e) {
                                e.printStackTrace();
                            }

 //code method decodeUri

private Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException {
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(
                getContentResolver().openInputStream(selectedImage), null, o);

        final int REQUIRED_SIZE = 100;

        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) {
                break;
            }
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        return BitmapFactory.decodeStream(
                getContentResolver().openInputStream(selectedImage), null, o2);
    }
0

There are 0 answers