I am working on a program that is essentially going to be a EXIF data stamper for exclusively JPEG images.
我正在开发一个程序,它本质上将成为专用JPEG图像的EXIF数据压模。
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:
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;
}
}
I am getting an error at {JPEGMetadata JPEGmeta = (JPEGMetadata metadata;}
"JPEGMetadata cannot be resolved to a type"
我收到错误{JPEGMetadata JPEGmeta =(JPEGMetadata metadata;}“JPEGMetadata无法解析为类型”
the original code was for a PNG so i replaced all PNG with JPEG with find/replace.
原始代码用于PNG,所以我用发现/替换用JPEG替换了所有PNG。
1 个解决方案
#1
23
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.
在编程中,您不仅可以将对象PNGMetadata的名称更改为JPEGMetadata并期望它可以工作。
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.
您可以看到,PNGMetadata对象的开发仅适用于PNG图像。您不能只将名称更改为JPEG并期望它适用于它。
If you need something to work for JPEGs, I can recommend a library to read JPEG metadata. See the link below.
如果你需要一些适用于JPEG的东西,我可以推荐一个库来读取JPEG元数据。请参阅以下链接。
https://drewnoakes.com/code/exif/
https://drewnoakes.com/code/exif/
#1
23
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.
在编程中,您不仅可以将对象PNGMetadata的名称更改为JPEGMetadata并期望它可以工作。
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.
您可以看到,PNGMetadata对象的开发仅适用于PNG图像。您不能只将名称更改为JPEG并期望它适用于它。
If you need something to work for JPEGs, I can recommend a library to read JPEG metadata. See the link below.
如果你需要一些适用于JPEG的东西,我可以推荐一个库来读取JPEG元数据。请参阅以下链接。
https://drewnoakes.com/code/exif/
https://drewnoakes.com/code/exif/