title: Android: wrong orientation of files opened with BitmapFactory.decodeFile
body: <p>Just simple as the title, files opened with BitmapFactory.decodeFile have wrong orientation when it is displayed on the ImageView. The image its captured from the camera and saved on a tmp file so if the device has the bug that returns data.getData() null I have at least a reference to the file. </p>
  
  <p>This just start the camera activity and capture the image file</p>
  
  <pre><code>private void startCamera() {
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      if (hasImageCaptureBug()) {
          intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Constants.TMPFILE_PATH)));
      } else {
          intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      }
      startActivityForResult(intent, CAMERA_PIC_REQUEST);
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == CAMERA_PIC_REQUEST) {
          if (resultCode == RESULT_OK) {
              Uri uri = null;
  
              if (hasImageCaptureBug()) {
                  File f = new File(Constants.TMPFILE_PATH);
                  try {
                      uri = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), f.getAbsolutePath(), null, null));
                  } catch (FileNotFoundException e) {
  
                  }
              } else {
                  uri = data.getData();
              }
  
              imageFilePath = Image.getPath(this, uri);
  
              if (Image.exists(imageFilePath)) {
                  ImageView image = (ImageView) findViewById(R.id.thumbnail);
                  int targetW     = (int) getResources().getDimension(R.dimen.thumbnail_screen_width);
                  int degrees     = (int) Image.getRotation(this, uri);
  
                  Bitmap bmp = Image.resize(imageFilePath, targetW);
                  bmp = Image.rotate(bmp, degrees);
  
                  image.setAdjustViewBounds(true);
                  image.setImageBitmap(bmp);
              }
          }
      }
  }
  </code></pre>
  
  <p>And this file resizes the image</p>
  
  <pre><code>public class Image {
      public static Bitmap resize(String pathName, int targetW) {
          BitmapFactory.Options opts = new BitmapFactory.Options();
          opts.inJustDecodeBounds = true;
  
          Bitmap bmp = BitmapFactory.decodeFile(pathName, opts);
  
          int photoW = opts.outWidth;
          int photoH = opts.outHeight;
          int targetH = Math.round((photoH * targetW) / photoW);
          int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
  
          opts.inJustDecodeBounds = false;
          opts.inSampleSize = scaleFactor;
          opts.inPurgeable = true;
  
          bmp = BitmapFactory.decodeFile(pathName, opts);
  
          return bmp;
      }
  }
  </code></pre>
  
  <p>Tryed to get the ExifOrientation but always its 0 because the file itself its correctly oriented just when I load it the file is displayed with the wrong orientation.</p>
  
  <p>Regards</p>