您不能使用 Input Stream 进行属性突变。
你可以查看 ExifInterface 的代码,上面写着:
/**
* Reads Exif tags from the specified image input stream. Attribute mutation is not supported
* for input streams. The given input stream will proceed its current position. Developers
* should close the input stream after use. This constructor is not intended to be used with
* an input stream that performs any networking operations.
*/
public ExifInterface(InputStream inputStream) throws IOException {
/* Irrelevant code here */
因此,如果您想写入文件的元数据,则需要在构造函数中传递文件。否则它将失败。您还可以在类中看到总是失败的代码(使用 InputStream):
public void saveAttributes() throws IOException {
if (!mIsSupportedFile || mMimeType != IMAGE_TYPE_JPEG) {
throw new IOException("ExifInterface only supports saving attributes on JPEG formats.");
}
if (mFilename == null) {
throw new IOException(
"ExifInterface does not support saving attributes for the current input.");
}
//Irrelevant code
因此,使用 ExifInterface(file),您将能够使您的代码工作。
快乐编码!