Android image resizing and preserving EXIF data (orientation, rotation, etc.)

后端 未结 5 1909
甜味超标
甜味超标 2020-12-04 10:55

If your Android app uses the device camera to take a picture and then resizes it (this is very, very common to reduce the size for upload), you might not realize that this r

5条回答
  •  佛祖请我去吃肉
    2020-12-04 11:35

    Why not just modify the ExifInterface source and add your own implementation to support reading/writing in bulk so you don't have to specify tag by tag. Here is a snippet of what I would do.

    Add new method to expose the internal attributes:

    public HashMap[] getAllAttributes() {
        return mAttributes;
    }
    

    Add new method to set all the attributes:

    public void setAttributes(HashMap[] attributes) {
        for (int i = 0 ; i < EXIF_TAGS.length; ++i) {
            mAttributes[i] = attributes[i];
        }
    }
    

    Then use it like this to preserve Exif and save to another File

    // Grab all the original exif attributes from an image file and save to memory or wherever
    let attributes = ExifInterface2(sourceImagePath).attributes
    
    // Later on you can just copy those attributes to another image
    ExifInterface2(destImagePath)
        .setAttributes(attributes)
        .saveAttributes();
    

提交回复
热议问题