1

I want to get orientation of a bitmap. i use this code:

ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,      
ExifInterface.ORIENTATION_NORMAL);

switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
    rotateImage(bitmap, 90);
    break;
case ExifInterface.ORIENTATION_ROTATE_180:
    rotateImage(bitmap, 180);
    break;
// etc.
}

My problem is this line:

ExifInterface ei = new ExifInterface(photoPath);

in this code photoPath is an String but i don't have any String path! i have a Bitmap loaded in memory inside a Bitmap! how i can set the path for ExifInterface ?

Fcoder
  • 9,066
  • 17
  • 63
  • 100

3 Answers3

0

how i can set the path for ExifInterface ?

You don't.

However, you also do not have any EXIF headers by the time you wind up with a Bitmap.

If you are attempting to apply this to a photo taken by the camera, and that photo is in JPEG format, the byte[] representing the encoded photo can be passed to the readExif() method of an ExifInterface object (created from the zero-argument constructor):

ExifInterface exif=new ExifInterface();

exif.readExif(data);

Otherwise, you may wish to explain where this Bitmap comes from.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • In API 19 sources, I don't see any method called readExif(), nor the parameterless constructor. :-( – david.perez Oct 17 '14 at 06:41
  • @david.perez: Ah, excellent point. I thought I was forgetting something. In my camera library, I am not using the SDK's `ExifInterface`, but the similarly-named class from the AOSP messaging client: https://github.com/commonsguy/cwac-camera/tree/master/camera/src/com/android/mms/exif – CommonsWare Oct 17 '14 at 10:48
0
  • The first solution it's to create a temporary file and call the standard new ExifInterface(tempFile). I don't like it for inefficient

  • Other solution is given here, but you have to make your APK bigger, by adding 3rd party code.

  • The solution I've personally chosen is to rotate the image when it is captured to a temporary file, and then save it in a blog field of a Sqlite database. Then at view time, I don't need to handle the rotation, and the problem of not being able to read the EXIF headers, as I don't have a file.

Community
  • 1
  • 1
david.perez
  • 6,090
  • 4
  • 34
  • 57
0
    private File createImageFile() throws IOException {
            // Create an image file name
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "JPEG_" + timeStamp + "_";
            File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
            File image = File.createTempFile(
                    imageFileName,  /* prefix */
                    ".jpg",         /* suffix */
                    storageDir      /* directory */
            );
    
            // Save a file: path for use with ACTION_VIEW intents
            currentPhotoPath = image.getAbsolutePath();
            return image;
        }

    File file=createImageFile() 
    pass file to ExifInteface


   
 photoURI = FileProvider.getUriForFile(YourActivity.this, getApplicationContext().getPackageName() + ".provider", file);

Make sure you click on the same file path
 intent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
Ambesh Tiwari
  • 648
  • 7
  • 11