use of ar.com.hjg.pngj.PngReader in project imageio-ext by geosolutions-it.
the class PNGWriterTest method testTeXt.
@Test
public void testTeXt() throws Exception {
PNGWriter writer = new PNGWriter();
OutputStream out = null;
File pngOut = null;
final String title = "Title";
final String description = "Sample Description";
final String software = "ImageIO-Ext";
final String author = "Me";
try {
// read test image
BufferedImage read = ImageIO.read(TestData.file(this, "sample.jpeg"));
pngOut = TestData.temp(this, "test.png", true);
out = new FileOutputStream(pngOut);
Map<String, String> textMetadata = new HashMap<String, String>();
textMetadata.put("Title", title);
textMetadata.put("Author", author);
textMetadata.put("Software", software);
textMetadata.put("Description", description);
writer.writePNG(read, out, 1, FilterType.FILTER_NONE, textMetadata);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
BufferedImage test = ImageIO.read(pngOut);
assertNotNull(test);
PngReader reader = null;
try {
reader = new PngReader(pngOut);
reader.readSkippingAllRows();
PngMetadata metadata = reader.getMetadata();
assertNotNull(metadata);
assertEquals(title, metadata.getTxtForKey("Title"));
assertEquals(description, metadata.getTxtForKey("Description"));
assertEquals(author, metadata.getTxtForKey("Author"));
assertEquals(software, metadata.getTxtForKey("Software"));
} finally {
if (reader != null) {
reader.close();
}
}
}
Aggregations