How to get Exif data from an InputStream rather than a File?

后端 未结 1 1863
情深已故
情深已故 2020-12-18 00:17

The reason why I am asking this is because the callback of the file chooser Intent returns an Uri.

Open file chooser via Intent:

         


        
相关标签:
1条回答
  • 2020-12-18 01:05

    After the 25.1.0 support library was introduced, now is possible to read exif data from URI contents (content:// or file://) through an InputStream.

    Example: First add this line to your gradle file:

    compile 'com.android.support:exifinterface:25.1.0'

    Uri uri; // the URI you've received from the other app
    InputStream in;
    try {
      in = getContentResolver().openInputStream(uri);
      ExifInterface exifInterface = new ExifInterface(in);
      // Now you can extract any Exif tag you want
      // Assuming the image is a JPEG or supported raw format
    } catch (IOException e) {
      // Handle any errors
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ignored) {}
      }
    }
    

    For more information check: Introducing the ExifInterface Support Library, ExifInterface.

    0 讨论(0)
提交回复
热议问题