android "android" 修改 jpg exif 属性,如何在Android中将exif数据写入图像?

我正在尝试使用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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值