我正在尝试列出与图库中的图像关联的所有 exif 属性。每个 getAttribute() 都返回 null。当我调试和检查 ExifInterface 时,它有一个有效文件,当我展开“mAttributes”节点时,“表”包含我正在寻找的所有 EXIF 数据,但“值”、“keySet”和“valuescollection” " 为空。知道我哪里出错了吗?
编辑:也许问题在于我如何获取文件名?我更新了下面的代码以提供更完整的图片。
//create an array of thumbnail IDs
String[] ids = {MediaStore.Images.Thumbnails._ID};
//this pulls the file locations
cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ids, null, null, MediaStore.Images.Thumbnails.IMAGE_ID);
colIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
//at this point we need to target the gridview.
GridView gallery = (GridView) findViewById(R.id.gridView1);
//borrowed an adapter provided in the tutorial at http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html
gallery.setAdapter(new ImageAdapter(this));
//now we attach a listener to our gridview.
gallery.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView parent, View v, int position, long id)
{
String[] ids = {MediaStore.Images.Media.DATA};
cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ids, null, null, null);
colIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
String image = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
ExifInterface clicked = null;
try {
clicked = new ExifInterface(image);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(clicked==null)
{
Toast.makeText(getApplicationContext() , "We were not able to load the file." , Toast.LENGTH_LONG).show();
}
else
{
TextView tv = (TextView) findViewById(R.id.messageCenter);
String message;
message = "Latitude: " + clicked.getAttribute(ExifInterface.TAG_GPS_LATITUDE) + "\n";
message += "Longitude: " + clicked.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) + "\n";
message += "Make: " + clicked.getAttribute(ExifInterface.TAG_MAKE) + "\n";
message += "Model: " + clicked.getAttribute(ExifInterface.TAG_MODEL) + "\n";
message += "Date/Time: " + clicked.getAttribute(ExifInterface.TAG_DATETIME) + "\n";
message += "Flash: " + clicked.getAttribute(ExifInterface.TAG_FLASH) + "\n";
message += "Flocal Length: " + clicked.getAttribute(ExifInterface.TAG_FOCAL_LENGTH) + "\n";
message += "White Balance: " + clicked.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
tv.setText(message);
}
}
});
这是运行时点击的样子
编辑:我发现调用表中列出的值是有效的。但是,如果我展开 mAttributes.table.[0].value.value 我要查找的其他信息列在 char 数组中。为什么不传递这些信息?