reading android jpeg EXIF metadata from picture callback

前端 未结 8 1828
天命终不由人
天命终不由人 2020-11-30 20:48

Background: I am writing a camera app for a messenger program. I cannot save the captured image to persistent disk at any time. The camera must support all orientations.

8条回答
  •  庸人自扰
    2020-11-30 21:39

    If you have a content:// type of Uri, android provides APIs through ContentResolver and there’s no need to use external libraries:

    public static int getExifAngle(Context context, Uri uri) {
        int angle = 0;
        Cursor c = context.getContentResolver().query(uri,
                new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
                null,
                null,
                null);
    
        if (c != null && c.moveToFirst()) {
            int col = c.getColumnIndex( MediaStore.Images.ImageColumns.ORIENTATION );
            angle = c.getInt(col);
            c.close();
        }
        return angle;
    }
    

    You can also read any other value you find in MediaStore.Images.ImageColumns, like latitude and longitude.

    This currently doesn’t work with file:/// Uris but can be easily tweaked.

提交回复
热议问题