0
我想为图像使用Exif标签。 阅读标签非常简单,它工作正常,但不保存。保存ExifInterface标签抛出IOException
private void saveTag(String tag, String value) {
try {
ExifInterface exif = new ExifInterface(imagePath);
exif.setAttribute(tag, value);
exif.saveAttributes();
} catch (IOException ioe) {
toast("Image no longer exists!");
} catch (NullPointerException npe) {
toast("No image loaded!");
}
}
每次抛出IOException,我该怎么办?
授予:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
你应该检查图像路径是什么。您可能正在使用不引用物理文件的File.getAbsolutePath()。 – Thracian
我通过intent选择了一个图像,获得了URI,转换为路径,读取TAG_DATETIME通过使用该路径工作,但不保存 – Andreisk
这就是问题所在。你没有file://的路径,你得到一个content://。看看这个[链接](https://stackoverflow.com/questions/46442700/writing-exif-data-to-image-saved-with-documentfile-class)。 – Thracian