小编Aus*_*ris的帖子

JPEGMetadata无法解析为某种类型

我正在开发一个程序,它本质上将成为专用JPEG图像的EXIF数据压模.

GUI将包含一个搜索框,一个加载按钮和一个显示EXIF数据的显示框.但我正在与读者讨论一个问题:

public class MetaRead {
    public String readCustomData(byte[] imageData, String key) throws IOException{
        ImageReader imageReader = ImageIO.getImageReadersByFormatName("JPEG").next();

        imageReader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(imageData)), true);

        // read metadata of first image
        IIOMetadata metadata = imageReader.getImageMetadata(0);

        //this cast helps getting the contents 

        JPEGMetadata JPEGmeta = (JPEGMetadata) metadata; 
        NodeList childNodes = JPEGmeta.getStandardTextNode().getChildNodes();

        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            String keyword = node.getAttributes().getNamedItem("keyword").getNodeValue();
            String value = node.getAttributes().getNamedItem("value").getNodeValue();
            if(key.equals(keyword)){
                return value;
            }
        }
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到错误 …

java jpeg exif metadata

4
推荐指数
1
解决办法
3848
查看次数

标签 统计

exif ×1

java ×1

jpeg ×1

metadata ×1