Hello people from stackoverflow,
I've spent some time googling for a solution to my problem, but nothing great came out.
I would like to write metadata to an image that I create from scratch.
My understanding of Java Advanced Image API is that I should use IIOMetadata but code snippets I found seemed to be overly complicated.
Then I searched a library and found Sanselan but it seems a bit old, and not very handy for writing metadata.
I actually create the image using ImageIO.write(image, "png", baos);
I understand image metadatas are a bit complex to handle due to its XML-like structure.
Could anybody point me to a tutorial, a solution, a library... ?
Thanks, Alexis.
Using the method from posted by the OP gets most of the way there; the only issue is that
PNGMetadata
is proprietary and so causes compiler warnings.There is a method of doing it without using the proprietary API, by searching the metadata tree for
tEXtEntry
nodes:Java provides the
metadata
package and theImageWriter
class along with theImageIO
package.You create your
IIOMetadata
object, thengetImageWriters
for yourBufferedImage
orIIOImage
and use them towrite
the metadata.To add to other answer, you can also try the PNGJ library, it has full metadata support.
BTW, I don't understand what you are refering to with the "XML-like" structure of metadata.
I had to do the the same thing some days ago.. I have not found the exact solution on the internet either but looking at the
com.sun.imageio.plugins.png.PNGMetadata
class I could achieve some results..To write a custom metadata to a PNG file:
Then, to read the data: