在学习如何向png图片中插入metaData 时候,发现了一个工具包,很好用,commons-imaging-1.0, 可以到网上搜索下载jar包。
这里写了一个简短的练习类,来学习, 实现的功能是读取图片的metadata,并插入到新图片中。
public static byte[] imageWriteExample(final File file)
throws ImageReadException, ImageWriteException, IOException {
// read image
final BufferedImage image = Imaging.getBufferedImage(file);
final ImageFormat format = ImageFormats.PNG;
ImageInfo imageInfo = Imaging.getImageInfo(file);
List<String> allComments = imageInfo.getComments();
List newComments = new ArrayList();
for (String items : allComments) {
System.out.println(items);
String[] item = items.split(":");
if (item[0].equals("view_nodes")) {
newComments.add(new PngText.Itxt(item[0], item[1], "utf-8", ""));
} else {
newComments.add(new PngText.Text(item[0], item[1]));
}
}
final Map<Stri