android img标签属性_为JPEG图片添加自定义标签(Android)

EXIF(Exchangeableimagefile format)为可交换图像文件的简称,是专门为数码相机的照片设定的,可以记录数码照片的属性信息和拍摄数据,EXIF可以附加于JPEG、TIFF、RIFF等文件之中(维基百科)。

有时候我们想在拍摄的图像中加入自定义的一些标注,而Andord SDK的Reference中的ExifInterface (http://developer.android.com/reference/android/media/ExifInterface.html)并没有包含所有的EXIF标签接口,我们可以用下面的方法把自定义的信息填到userComment这一标签里。

Button.OnClickListener takePicBtnListener = new Button.OnClickListener() {

//@Override

public void onClick(View v) {

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

UUID id = UUID.randomUUID();

imgPath = rootPath + id.toString() + ".jpg";

File imgFile = new File(imgPath);

try {

if(!imgFile.exists())

imgFile.createNewFile();

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imgFile));

} catch (IOException e) {

e.printStackTrace();

imgFile = null;

}

startActivityForResult(takePictureIntent,0);

}

};

Button.OnClickListener showUsrCmtBtnListener = new Button.OnClickListener() {

//@Override

public void onClick(View v) {

try {

ExifInterface exif = new ExifInterface(imgPath);

showDialog(exif.getAttribute("UserComment"));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

};

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {

try {

ExifInterface exif = new ExifInterface(imgPath);

String mString = "Beijing";

exif.setAttribute("UserComment", mString);

exif.saveAttributes();

}catch(IOException e){

e.printStackTrace();

}

}

}

private void showDialog(String msg)

{

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage(msg);

AlertDialog alert = builder.create();

alert.show();

}注:代码中的“UserComment”字段不能随意更改(如改成“UserCmt”),因为“UserComment”是EXIF的标准tag。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值