获取图像的元数据 - Android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12623302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Meta Data of Image - Android
提问by RVG
http://www.isco.com/webproductimages/appBnr/bnr1.jpg
http://www.isco.com/webproductimages/appBnr/bnr1.jpg
I've used a websiteto see the metadata of a image. In this website, it shows all info of image. I want to know how to get the "Title" tag of above image in android.
我使用过一个网站来查看图像的元数据。在这个网站上,它显示了图像的所有信息。我想知道如何在 android 中获取上图的“标题”标签。
I found here the similiar question for iOS only: How to get image metadata in ios
我在这里找到了仅适用于 iOS 的类似问题:How to get image metadata in ios
However I don't know how to get "Meta data" of image on android. ExifInterface
only gives some informations. But I'm unable to get "Title" tag with it.
但是我不知道如何在 android 上获取图像的“元数据”。ExifInterface
只提供一些信息。但我无法获得“标题”标签。
Can you provide any code snippet for get meta data in android for image?
你能提供任何代码片段来在android中获取图像的元数据吗?
回答by Venkatesh S
Download metadata extractor from the link given here ...... click to download the librarychoose the version 2.5.0.RC-3.zip
从这里给出的链接下载元数据提取器......点击下载库选择版本 2.5.0.RC-3.zip
Extract the jar Folder
解压jar文件夹
and import jar into libs folder in your poject and then execute the below code
并将 jar 导入项目中的 libs 文件夹,然后执行以下代码
try {
InputStream is = new URL("your image url").openStream();
BufferedInputStream bis = new BufferedInputStream(is);
Metadata metadata = ImageMetadataReader.readMetadata(bis,true);
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
System.out.println(tag);
}
}
}
catch (ImageProcessingException e){}
catch (IOException e) {}
回答by Korhan Ozturk
If you want to retrieve meta data information about an image ExifInterfaceis what you are looking for. Here is a quite good example of how this interface is used: http://android-er.blogspot.com/2009/12/read-exif-information-in-jpeg-file.html
如果您想检索有关图像的元数据信息,ExifInterface就是您要查找的内容。这里有一个很好的例子来说明如何使用这个接口:http: //android-er.blogspot.com/2009/12/read-exif-information-in-jpeg-file.html
But if you want to retrieve information of an online image I'm afraid it's not yet possible.
但是,如果您想检索在线图像的信息,恐怕还不可能。
回答by Sahil Bansal
If you want to retrieve metadata from image in Android project, then you can do that with the help of: https://github.com/drewnoakes/metadata-extractor
如果你想从 Android 项目中的图像中检索元数据,那么你可以在以下帮助下完成:https: //github.com/drewnoakes/metadata-extractor
Implement this in your gradle using
使用
implementation 'com.drewnoakes:metadata-extractor:2.12.0'
Complete code is as follows
完整代码如下
private static String getImageMetaData(Uri image1) {
try {
InputStream inputStream = FILE_CONTEXT.getContentResolver().openInputStream(image1);
try {
image1.getEncodedUserInfo();
Metadata metadata = ImageMetadataReader.readMetadata(inputStream);
for (Directory directory1 : metadata.getDirectories()) {
if (directory1.getName().equals("Exif IFD0")) {
for (Tag tag : directory1.getTags()) {
if (tag.getTagName().equals("Date/Time")) {
return tag.getDescription();
}
}
}
}
} catch (ImageProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}