使用ExifInterface获取图片信息

 1 package com.example.readimage;
 2 
 3 import java.io.IOException;
 4 
 5 import android.media.ExifInterface;
 6 import android.os.Bundle;
 7 import android.os.Environment;
 8 import android.annotation.SuppressLint;
 9 import android.app.Activity;
10 import android.view.Menu;
11 import android.view.View;
12 
13 public class MainActivity extends Activity {
14 
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19     }
20 
21     public void read(View view){
22        try {
23            String path = Environment.getExternalStorageDirectory().getPath();
24            System.out.println(path);
25             ExifInterface exif = new ExifInterface(path+"/aa.jpg");
26             System.out.println(exif);
27             //
28             String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
29             System.out.println(width);
30             String time = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
31             System.out.println(time);
32             //拍摄设备
33             /*String mode = exif.getAttribute(ExifInterface.TAG_MODEL);
34             System.out.println(mode);*/
35        } catch (IOException e) {
36            // TODO Auto-generated catch block
37            e.printStackTrace();
38        }
39    }
40     
41 }

注意:有些数据是获取不到的,并且容易报错

posted @ 2016-04-01 14:11  zhongyinghe  阅读(798)  评论(0编辑  收藏  举报