问题
I'm trying to save metadata, but it doesn't get saved, an i don't get any errors either. The image get saved correctly. I'm using the PNGJ library.
Reading metadata, (and the image) works correctly, and i'm checking with imagemagick.
The code is:
ImageInfo imi = new ImageInfo(size.x, size.y, 8, true);
PngWriter pngW = new PngWriter(outputStream, imi);
pngW.setCompLevel(compressionLevel);
pngW.getMetadata().setText(PngChunkTextVar.KEY_Title, "My image");
ImageLineInt iline = new ImageLineInt(imi);
for (int row = 0, c = 0; row < pngW.imgInfo.rows; row++) {
for (int col = 0; col < imi.cols; col++) {
int r = image[c++] & 0xFF, g = image[c++] & 0xFF, b = image[c++] & 0xFF, a = image[c++] & 0xFF;
ImageLineHelper.setPixelRGBA8(iline, col, r, g, b, a);
}
pngW.writeRow(iline);
}
pngW.end();
Why isn't the metadata get saved, or why don't i get an error message?
回答1:
In the PNG format, textual chunks have no restriction about its position in the chunks sequence: they can be placed after the IDAT chunks (pixels data). That's because it's assumed that textual metadata should not be needed (or influence) the image display.
The PngWriter for the PNGJ library puts the metadata chunks in a queue, to be written (by default) as late as legal/possible. In practice, this means that Textual chunks will be written after the IDAT chunks. If you don't want this, you should first ask yourself if you really want to put image information (that you need to display the image) in a textual chunk, that sounds broken. Anyway, if you want to force the textual chunk to be written as early as possible, simply set the priority to true: PngChunk.setPriority()
来源:https://stackoverflow.com/questions/24871638/pngj-metadata-doesnt-get-saved