【发布时间】:2015-02-28 05:33:11
【问题描述】:
我正在尝试使用 exif 接口将 User_Comment 和 TAG_GPS 写入 Android 应用程序中捕获的图像,但由于某种原因,当我查看图片在图库中的详细信息。
似乎标签没有被写入捕获的图像,因为文件路径可能是错误的。我认为这可能是因为我将标签写入了错误的图像路径。
有谁知道我将标签写入图像的方式是否存在问题?
这是在@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;
}
【问题讨论】:
-
为什么要多次调用 exif.saveAttributes?我相信每次都会创造一个新的形象。只是想知道
-
有可能,我有一段时间没有从事这个项目了,我认为问题可能是数据被保存到名为“exif”的临时图像中,并且从未写入原图。
标签: java android exif android-gallery android-camera-intent