我正在开发一个程序,它本质上将成为专用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)
我收到错误 …