Get Meta Data of Image - Android

前端 未结 3 548
甜味超标
甜味超标 2020-11-30 13:31

http://www.isco.com/webproductimages/appBnr/bnr1.jpg

I\'ve used a website to see the metadata of a image. In this website, it shows all info of image. I want to know

相关标签:
3条回答
  • 2020-11-30 13:41

    If you want to retrieve meta data information about an image ExifInterface is 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

    But if you want to retrieve information of an online image I'm afraid it's not yet possible.

    0 讨论(0)
  • 2020-11-30 13:50

    Download metadata extractor from the link given here ...... click to download the library choose the version 2.5.0.RC-3.zip

    Extract the jar Folder

    and import jar into libs folder in your poject and then execute the below code

            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) {}
    
    0 讨论(0)
  • 2020-11-30 13:54

    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

    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;
    }
    
    0 讨论(0)
提交回复
热议问题