我正在尝试使用exif界面在Android应用程序中为捕获的图像编写User_Comment和TAG_GPS,但由于某种原因,当我在图库中查看图像的详细信息时,标记似乎没有附加到图像上.
似乎可能没有将标签写入捕获的图像,因为文件路径可能是错误的.我想这可能是因为我将标签写入了错误的图像路径.
有谁知道我的标签写入图像的方式是否有问题?
这是在@ Charlie的更改后保存exif数据的代码:
private File getOutputPhotoFile() throws IOException {
File directory = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), getPackageName());
if (!directory.exists()) {
if (!directory.mkdirs()) {
Log.e(TAG, "Failed to create storage directory.");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
File[] files = directory.listFiles();
File exifVar = new File(directory.getPath(), "IMG_" + timeStamp + ".jpg");
if(files.length!=0) {
File newestFile = files[files.length-1];
exifVar = new File(directory.getPath() + File.separator + newestFile.getName());
}
String mString = "Generic Text..";
ExifInterface exif = new ExifInterface(exifVar.getAbsolutePath());
exif.setAttribute("UserComment", mString);
exif.saveAttributes();
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
String.valueOf(latituteField.toString()));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,
String.valueOf(longitudeField.toString()));
exif.saveAttributes();
return exifVar;
}