title: Image Orientation - Android
body: <p>I have been struggling with this bug on and off for the last month or so. Everytime that I think I have fixed it it seems to come back in some form.</p>
  
  <p>It is the old Android "Image Rotated 90 degrees" bug. I have read countless Posts on here (StackOverFlow) aswell as tried numerous methods but just cannot seem to fix it.</p>
  
  <p>I am still getting images that are rotated incorrectly.</p>
  
  <p>In my application a user chooses his/her profile Picture, which is then set to an ImageView. The image is chosen from the Phones Gallery</p>
  
  <p>Two days ago I implemented the Following Code, this worked for all the images I tested it with on my Phone. However when one of my Beta testers tried it, his images were once again rotated. He sent me the images for testing but they were displaying fine on my Phone. Hence why I am getting more and more frustrated.</p>
  
  <p>This is the method I am using to get the Images orientation:</p>
  
  <pre><code>// Gets an Images Orientation
  public static int getOrientationEXIF(Context context, Uri uri) {
  
      int orientation = 0;
  
      try {
  
          ExifInterface exif = new ExifInterface(uri.getPath());
  
          orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  
          switch (orientation) {
  
              case ExifInterface.ORIENTATION_ROTATE_90:
                  orientation = 90;
                  return orientation;
  
              case ExifInterface.ORIENTATION_ROTATE_180:
                  orientation = 180;
                  return orientation;
  
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I then get a rotated Bitmap using this Method:</p>
  
  <pre><code>// Rotate a Bitmap
  public static Bitmap rotate(float rotationValue, String filePath) {
      Bitmap original= BitmapFactory.decodeFile(filePath);
  
      int width = original.getWidth();
  
      int height = original.getHeight();
  
      Matrix matrix = new Matrix();
  
      matrix.postRotate(rotationValue);
  
      Bitmap rotated = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true);
  
      return rotated;
  }
  </code></pre>
  
  <p>I am just not sure what to do anymore.</p>
  
  <p>I would really like it if someone could help me figure this out</p>
  
  <p>Thank you in advance</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I just saw the following line of Code in my Log after implementing the suggested Methods:</p>
  
  <pre><code>JHEAD can't open 'file:/external/images/media/3885'
  </code></pre>
  
  <p>I am not sure what this means</p>
  
  <hr>
  
  <p><strong>UPDATE #2</strong></p>
  
  <p>I think I may have fixed the problem, I got the proper image path for the file.</p>