0

lets say I have an image in my gallery or any other directory called (image1), if I make an intent and choose that image, then I must get a uri returned in onActivityResult() call back.

Problem

If I change the uri to bitmap and display the bitmap in an image view, somehow the device decides to rotate the original image, example when picking image 1:

     onActivityResult(){

      //uri of image 1
      Uri uri=data.getData();

      //if I change to bitmap

      Bitmap bitmap=changeUriToBitmap(uri);

      //display in imageview

      imageview.setBitmap(bitmap);

       //I will get a rotated image

     }

After researching

I found out that some devices rotate the image automatically for some reason, a certain fix is to get orientation EXIF data for the image and check the if (90,180,270) and rotate accordingly to get a proper viewing.

To get the EXIF DATA we must do this:

  ExifInterface exif=new ExifInterface(path_of_image1);
  int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

My problem is getting (path_of_image1).

I know that others did it using cursor and stuff like that, But I want to achieve it another way:

The Other way that I want to use

       onActivityResult(){

  //get uri of image 1
  Uri uri=data.getData();

  //change to bitmap

  Bitmap bitmap=changeUriToBitmap(uri);

  //save to file called (file) using output stream
  File file=new File(path);
  .............
  ............
  //now image1 is in (file)

  //get the file path

  String path=file.getAbsolutePath();

  //get EXIF DATA

   ExifInterface exif=new ExifInterface(path);
  int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);



 }

My Question

If I used the other way by storing image1 in a file, does it mean that the original EXIF data that came from the gallery or where ever the image1 will stay constant or they will change after saving image1 in the file?

In other words are EXIF data unique for every image or they can be changed?

Hasan Bou Taam
  • 4,017
  • 2
  • 12
  • 22
  • Confused about your formulation of a problem. It does not matter where your image file comes from. No one will touch a file when copied to a different location. And if you manage to read the exif header it will allways be the same. It is pretty unclear what you are doing. – greenapps Mar 04 '18 at 08:22
  • `//save to file called (file) using output stream`. Yes. Ok. But pretty unclear what you want to save to file. – greenapps Mar 04 '18 at 08:28

0 Answers0