我一直在尝试从 APNG 文件中提取所有 png 文件。我已经寻求帮助,而且没有太多。我能找到的只是一个开源库 pngj,有了它,我就可以获得 APNG 文件的第一帧。
这是我正在使用的代码
public static void mirror(File orig, File dest, boolean overwrite)
{
PngReader pngr = FileHelper.createPngReader(orig);
PngWriter pngw = FileHelper.createPngWriter(dest, pngr.imgInfo,
overwrite);
pngw.setFilterType(FilterType.FILTER_CYCLIC); // just to test all
// filters
int copyPolicy = ChunkCopyBehaviour.COPY_ALL;
pngw.copyChunksFirst(pngr, copyPolicy);
ImageLine lout = new ImageLine(pngw.imgInfo);
int cols = pngr.imgInfo.cols;
int channels = pngr.imgInfo.channels;
int[] line = new int[cols * channels];
int aux;
for (int row = 0; row < pngr.imgInfo.rows; row++) {
ImageLine l1 = pngr.readRow(row);
line = l1.unpack(line, false);
for (int c1 = 0, c2 = cols - 1; c1 < c2; c1++, c2--) {
for (int i = 0; i < channels; i++) {
aux = line[c1 * channels + i];
line[c1 * channels + i] = line[c2 * channels + i];
line[c2 * channels + i] = aux;
}
}
lout.pack(line, false);
pngw.writeRow(lout, row);
}
pngr.end();
pngw.copyChunksLast(pngr, copyPolicy);
pngw.end();
// // print unknown chunks, just for information
List<PngChunk> u = ChunkHelper.filterList(pngr.getChunksList()
.getChunks(), new ChunkPredicate() {
public boolean match(PngChunk c) {
return ChunkHelper.isUnknown(c);
}
});
if (!u.isEmpty())
System.out.println("Unknown chunks:" + u);
}
所以基本上我只是镜像一个 apng 文件,它被转换成一个 png 文件,这是第一帧。那么有人可以告诉我如何获取剩余的帧并将它们保存为 png 文件吗?任何帮助或提示都会被应用