【发布时间】:2016-03-13 05:48:35
【问题描述】:
我正在尝试使用 PNGJ 库添加自定义元数据,tEXT
在 Android 中,我执行以下操作
Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
output.compress(Bitmap.CompressFormat.PNG, 100, stream);
有没有可能在PNGJ中做这样的事情
Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
//Add custom meta-data here
//Save the PNG file with PNGJ here using output
到目前为止,我所做的就是这样,
Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
ImageInfo imi = new ImageInfo(bitmap.getWidth(), bitmap.getHeight(), 16, true);
PngWriter png = new PngWriter(stream, imi);
png.getMetadata().setDpi(100.0);
png.getMetadata().setTimeNow(0);
png.getMetadata().setText(PngChunkTextVar.KEY_Title, "testing");
png.getMetadata().setText("Custom Key", "some text");
//Not sure how to connect the bitmap above to the PngWriter here
第二种方法,稍后添加标签
public void addTag(File orig, File dest, boolean overwrite) {
PngReader pngr = new PngReader(orig);
PngWriter pngw = new PngWriter(dest, pngr.imgInfo, overwrite);
pngw.copyChunksFrom(pngr.getChunksList(), ChunkCopyBehaviour.COPY_ALL_SAFE);
pngw.getMetadata().setText("appkey", "I'm value", true, false);
for (int row = 0; row < pngr.imgInfo.rows; row++) {
ImageLineInt line = (ImageLineInt) pngr.readRow(row);
pngw.writeRow(line, row);
}
pngr.end();
pngw.end();
}
现在,当我试图用它来获得它时,我什么也没得到
PngReader reader = new PngReader(new File(fileName1));
Log.d("pngkey", "value is: " + reader .getMetadata().getTxtForKey("appkey"));
请注意,当我使用以下内容检查 png 时,我确实看到添加了新标签
pngcheck -c -v -t image.png
【问题讨论】: