为JPEG图片添加自定义标签(Android)
来源:互联网 发布:flash mac版 编辑:程序博客网 时间:2024/06/08 13:28
EXIF(Exchangeable image file 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() { //@Overridepublic 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() {//@Overridepublic void onClick(View v) {try {ExifInterface exif = new ExifInterface(imgPath);showDialog(exif.getAttribute("UserComment"));} catch (IOException e) {// TODO Auto-generated catch blocke.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。
- 为JPEG图片添加自定义标签(Android)
- Android使用自定义ImageView为图片添加边框
- Android自定义EditText添加图片
- JSP自定义标签之三:为标签添加属性
- JSP自定义标签之三:为标签添加属性
- android 为图片添加倒影
- Android 为图片添加水印
- Android图片添加标签:Android-PictureTagView
- 为android自定义控件添加自定义属性
- 为集成在spring中的freemarker添加自定义标签
- 为集成在spring中的freemarker添加自定义标签
- 利用[Event]元标签为自定义事件添加代码提示
- Android为自定义控件添加事件
- Android为自定义控件添加事件
- Android自定义图片添加器-ZzImageBox
- 自定义控件—AndroidTagView标签,可在标签中添加图片,控制图片的位置
- 提取视频文件首帧为jpeg 图片
- YUV420P像素数据编码为JPEG图片
- MAT 安装URL 利用eclipse的update功能
- POJ 1067 取石子游戏
- android 中字符串转换
- extern深度解析
- 无根证书时访问 https
- 为JPEG图片添加自定义标签(Android)
- 大整数模板
- Linux系统基础命令
- 解析#pragma指令
- Gulliver's Travels——9、Gulliver escapes from Brobdingnag
- 如何理解LTE物理层的时隙结构,RE和RB
- 使用eclipse调试cocos2d-x C++ 代码(编写+真机调试,放弃VS)
- java nio server和lua client (B)
- HUNNU11342:Chemistry(模拟)