我试图列出与图库中的图像相关的所有 exif 属性。每个 getAttribute() 都返回 null。当我调试和检查 ExifInterface 时,它有一个有效文件,当我展开“mAttributes”节点时,“表”包含我正在寻找的所有 EXIF 数据,但“值”、“键集”和“值集合” "为空。知道我哪里出错了吗?
编辑:也许问题在于我如何获取文件名?我已经更新了下面的代码以提供更完整的图片。
//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,我正在寻找的其他信息会列在一个字符数组中。为什么这些信息没有传递出去?
最佳答案
您必须怀疑用于编辑图像的任何软件。即使它只是您用来以不同格式保存它的“查看器”。有些人会破坏 EXIF,有些人会将其全部剥离。此外,即使您认为 EXIF 是一种标准,但制造商之间在实现和命名标签的精确度方面存在很大差异。有一个名为 ExifTool 的工具,您不仅可以使用它来转储 EXIF,还可以对其进行修改和标准化。也许您可以将其嵌入到您的流程中或从您的代码中调用它。
关于android - EXIF getAttributes 返回 null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12083041/