PNGj,未保存元数据 [英] PNGj, metadata doesn't get saved

查看:254
本文介绍了PNGj,未保存元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存元数据,但是没有保存,我也没有任何错误. 图像被正确保存. 我正在使用PNGJ库.

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.

读取元数据(和图像)可以正常工作,我正在使用imagemagick进行检查.

Reading metadata, (and the image) works correctly, and i'm checking with imagemagick.

代码是:

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();

为什么不保存元数据,或者为什么我没有收到错误消息?

推荐答案

在PNG格式中,文本块对其在块序列中的位置没有限制:它们可以放在IDAT块(像素数据)之后.这是因为假设不需要文本元数据(或影响图像显示).

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.

PNGJ 库的PngWriter将元数据块放入队列中,以便编写(默认情况下),直到合法/可行为止.实际上,这意味着将在IDAT块之后写入Textual块.如果您不想这样做,首先应该问自己是否真的想将图像信息(需要显示图像)放在文本块中,这听起来很糟糕.无论如何,如果要强制尽早编写文本块,只需将优先级设置为true:

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()

这篇关于PNGj,未保存元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆