无法通过 Nougat 上的 URI 使用 ExifInterface 对象更改图像的 LatLng
Can't change LatLng of an image using ExifInterface object, via URI on Nougat
我正在设计一个 android 程序来更改图像的 LatLng。 Images Uri在一个Array中代码如下
发生的异常说
"ExifInterface does not support saving attributes for the currrent input"
InputStream in = getContentResolver().openInputStream((Uri)AddArray[i]);
ExifInterface ei = new ExifInterface(in);
ei.setAttribute(TAG_GPS_LATITUDE, "80/1,35/1,4091/100");
ei.setAttribute(TAG_GPS_LATITUDE_REF, "N");
ei.setAttribute(TAG_GPS_LONGITUDE, "45/1,1/1,4390/100");
ei.setAttribute(TAG_GPS_LONGITUDE_REF, "E");
try {
ei.saveAttributes();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Something went wrong" + e.getMessage(), Toast.LENGTH_LONG).show();
}
ExifInterface
,在您使用它时,只有一个 InputStream
,因此它无法保存您的更改。
您需要:
使用 InputStream
将 Uri
标识的内容复制到您控制的某个文件(例如,在 getCacheDir()
中)
对该文件使用 ExifInterface
,保存对该文件的更改
在ContentResolver
上使用openOutputStream()
在Uri
标识的内容上得到一个OutputStream
,然后将文件的字节复制到OutputStream
我正在设计一个 android 程序来更改图像的 LatLng。 Images Uri在一个Array中代码如下
发生的异常说
"ExifInterface does not support saving attributes for the currrent input"
InputStream in = getContentResolver().openInputStream((Uri)AddArray[i]);
ExifInterface ei = new ExifInterface(in);
ei.setAttribute(TAG_GPS_LATITUDE, "80/1,35/1,4091/100");
ei.setAttribute(TAG_GPS_LATITUDE_REF, "N");
ei.setAttribute(TAG_GPS_LONGITUDE, "45/1,1/1,4390/100");
ei.setAttribute(TAG_GPS_LONGITUDE_REF, "E");
try {
ei.saveAttributes();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Something went wrong" + e.getMessage(), Toast.LENGTH_LONG).show();
}
ExifInterface
,在您使用它时,只有一个 InputStream
,因此它无法保存您的更改。
您需要:
使用
InputStream
将Uri
标识的内容复制到您控制的某个文件(例如,在getCacheDir()
中)对该文件使用
ExifInterface
,保存对该文件的更改在
ContentResolver
上使用openOutputStream()
在Uri
标识的内容上得到一个OutputStream
,然后将文件的字节复制到OutputStream