I am working on a program that is essentially going to be a EXIF data stamper for exclusively JPEG images.
The GUI is going to consist of a search box a load button and a display box to display the EXIF data. But i am running into an issue with the reader:
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;
}
}
I am getting an error at {JPEGMetadata JPEGmeta = (JPEGMetadata metadata;}
"JPEGMetadata cannot be resolved to a type"
the original code was for a PNG so i replaced all PNG with JPEG with find/replace.
Okay, well. I don't know how to explain this without being blunt.
In programming, you can't just change the name of the object PNGMetadata
to JPEGMetadata
and expect it to work.
You see, the object PNGMetadata
is developed to work for and ONLY for PNG images. You can't just change the name to JPEG and expect it to work for it.
If you need something to work for JPEGs, I can recommend a library to read JPEG metadata. See the link below.
https://drewnoakes.com/code/exif/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With