A final answer on how to get Exif data from URI

前端 未结 4 1199
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 12:18

This topic has been discussed in lots of questions here, with mostly different results and, due to API changes and different types of URIs, no definitive answer

4条回答
  •  长发绾君心
    2020-12-28 13:03

    Don't use EXIF. You can get orientation of image from Uri like this:

    private static int getOrientation(Context context, Uri photoUri) {
        Cursor cursor = context.getContentResolver().query(photoUri,
                new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
    
        if (cursor.getCount() != 1) {
            cursor.close();
            return -1;
        }
    
        cursor.moveToFirst();
        int orientation = cursor.getInt(0);
        cursor.close();
        cursor = null;
        //orientation here can be 90, 180, 270!
    }
    

提交回复
热议问题