Get Meta Data of Image - Android

前端 未结 3 569
甜味超标
甜味超标 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: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;
    }
    

提交回复
热议问题