0

I have now implemented `ExifInterface, but it doesn't seem to rotate any of the images taken by the camera intent. The images are still returning in landscape instead of portrait.

Here is my code:

Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
     File imagesFolder = new File(Environment.getExternalStorageDirectory(), "My Fodler");
     imagesFolder.mkdirs();
     File image = new File(imagesFolder, "My_" + timeStamp + ".jpg");
     fileUri = Uri.fromFile(image);
     ExifInterface exif = null;
    try {
        exif = new ExifInterface(image.getAbsolutePath());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
        }
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
 startActivityForResult(imageIntent, TAKE_PICTURE);
}

What am I doing wrong here? Please help?

Allrounder
  • 685
  • 2
  • 9
  • 20
  • this is second time your are asking right about this orientation ? – J.K Dec 18 '14 at 11:55
  • http://stackoverflow.com/questions/27542693/how-to-change-the-orientation-of-image-taken-by-camera-intent/27542902#27542902 – J.K Dec 18 '14 at 11:56

1 Answers1

0

First, you are using ExifInterface to examine a file that does not yet exist. Wait until the camera app has taken the picture, so the file exists, then use ExifInterface.

Second, you are reading the EXIF header and setting rotate... then are doing nothing with the rotate value. Follow the instructions in the up-voted answers to their previous SO question and use Matrix to actually rotate the image. Note that you may not have enough heap space to rotate the full camera image, as they are huge -- rotate a downsampled one if possible.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hi Thanks, I have done as suggested and am happy to inform that it is working a 100% now thanks. One more problem to go and that is to save the image to that specific marker placed on the map after camera intent(you actually helped with that awhile ago) I have asked a question on that. The question is here if you want to have a look (and maybe help:-) ? (http://stackoverflow.com/questions/27427152/hashmap-not-returning-image-to-marker-by-onmarkerclick) Thanks again for your help I really appreciate it!! – Allrounder Dec 18 '14 at 12:34