title: Android image from gallery wrong orientation
body: <p>I am using an intent to load an image from the Android gallery. On a few of the devices I have tried it works fine but it seems on some devices the images loads in the wrong orientation. It's usually displayed in landscape instead of portrait. </p>
  
  <p>I did some searching and found a few suggestions regarding EXIF data and tried the following:</p>
  
  <pre><code>            if(resultCode == RESULT_OK){
  
                  Uri selectedImage = data.getData();
                  String[] filePathColumn = {MediaStore.Images.Media.DATA};
  
                  Cursor cursor = getContentResolver().query(
                                     selectedImage, filePathColumn, null, null, null);
                  cursor.moveToFirst();
  
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  String filePath = cursor.getString(columnIndex);
                  cursor.close();
  
                  String myFile = selectedImage.toString();
                  int orientation = 0;
                  try {
                      ExifInterface exif = new ExifInterface(myFile);
                      orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
                  Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
                  Bitmap rotatedBitmap = null;
                  Matrix matrix = new Matrix();
  
                  switch(orientation){
  
                      case 3:
  
                          matrix.postRotate(180);
                          break;
  
                      case 6:
  
                          matrix.postRotate(90);
                          break;
  
                      case 8:
  
                          matrix.postRotate(270);
                          break;
  
                  }
  
                  rotatedBitmap = Bitmap.createBitmap(yourSelectedImage, 0, 0, yourSelectedImage.getWidth(), yourSelectedImage.getHeight(), matrix, true);
                  _mJazzView.setBackground(rotatedBitmap);
  
              }
  </code></pre>
  
  <p>This did not resolve the issue and after trying several variations from further searching I can't seem to get it to load in the correct orientation. </p>
  
  <p>Any help would be great!</p>