Get image rotation using filedescriptor and parcelfiledescriptor in android from gallery

I want to get an image with a device higher than Android kitkat. I am currently using filedescriptor and parcelfiledescriptor to get the image. I get the image successfully but rotated. Since the image is stored in google drive, I cannot use the input stream directly. How can I solve this? (I know that image data is usually stored in exif, but if I try to get exif data then rotation is always 0) I also tried using lib: https://github.com/coomar2841/image-chooser-library , but i am getting the same problem here.

           ParcelFileDescriptor parcelFileDescriptor;
        try {
            parcelFileDescriptor = activity.getContentResolver().openFileDescriptor(selectedImage, "r");

            FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();

            Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
            image = ExifUtil.rotateBitmap(selectedImagePath, image);
            parcelFileDescriptor.close();
            if (cropCircle) {
                imageView.setImageBitmap(ImageUtils.cutCircle(image));
            } else {
                imageView.setImageBitmap(image);
            }
            return image;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

      

+3


source to share





All Articles