本文整理汇总了Java中com.sun.imageio.plugins.png.PNGMetadata类的典型用法代码示例。如果您正苦于以下问题:Java PNGMetadata类的具体用法?Java PNGMetadata怎么用?Java PNGMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PNGMetadata类属于com.sun.imageio.plugins.png包,在下文中一共展示了PNGMetadata类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PNGImageWriterSpiBackport
import com.sun.imageio.plugins.png.PNGMetadata; //导入依赖的package包/类
public PNGImageWriterSpiBackport() {
super(vendorName,
version,
names,
suffixes,
MIMETypes,
writerClassName,
new Class<?>[] { ImageOutputStream.class },
readerSpiNames,
false,
null, null,
null, null,
true,
PNGMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.png.PNGMetadataFormat",
null, null
);
}
示例2: writeWithMetadata
import com.sun.imageio.plugins.png.PNGMetadata; //导入依赖的package包/类
public static void writeWithMetadata(RenderedImage image, OutputStream os, String metadata, int dpi,
String debugData) throws IOException {
// Create & populate metadata
final PNGMetadata pngMetadata = new PNGMetadata();
if (dpi != 96) {
pngMetadata.pHYs_present = true;
pngMetadata.pHYs_unitSpecifier = PNGMetadata.PHYS_UNIT_METER;
pngMetadata.pHYs_pixelsPerUnitXAxis = (int) Math.round(dpi / .0254 + 0.5);
pngMetadata.pHYs_pixelsPerUnitYAxis = pngMetadata.pHYs_pixelsPerUnitXAxis;
}
if (metadata != null) {
pngMetadata.zTXt_keyword.add("plantuml");
pngMetadata.zTXt_compressionMethod.add(new Integer(0));
pngMetadata.zTXt_text.add(metadata);
}
if (debugData != null) {
pngMetadata.tEXt_keyword.add("debug");
pngMetadata.tEXt_text.add(debugData);
}
pngMetadata.tEXt_keyword.add("copyleft");
pngMetadata.tEXt_text.add(copyleft);
Log.debug("PngIOMetadata pngMetadata=" + pngMetadata);
// Render the PNG to file
final IIOImage iioImage = new IIOImage(image, null, pngMetadata);
Log.debug("PngIOMetadata iioImage=" + iioImage);
// Attach the metadata
final ImageWriter imagewriter = getImageWriter();
Log.debug("PngIOMetadata imagewriter=" + imagewriter);
// See http://plantuml.sourceforge.net/qa/?qa=4367/sometimes-missing-response-headers-for-broken-png-images
// Code provided by Michael Griffel
synchronized (imagewriter) {
final ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(os);
imagewriter.setOutput(imageOutputStream);
try {
imagewriter.write(null /* default */, iioImage, null /* use default ImageWriteParam */);
} finally {
//os.flush();
// Log.debug("PngIOMetadata finally 1");
imageOutputStream.flush();
// Log.debug("PngIOMetadata finally 2");
imageOutputStream.close();
// Log.debug("PngIOMetadata finally 3");
imagewriter.reset();
// Log.debug("PngIOMetadata finally 4");
imagewriter.dispose();
// Log.debug("PngIOMetadata finally 5");
}
}
}
示例3: writeWithMetadata
import com.sun.imageio.plugins.png.PNGMetadata; //导入依赖的package包/类
public static void writeWithMetadata(RenderedImage image, OutputStream os, String metadata, int dpi, String debugData) throws IOException {
// Create & populate metadata
final PNGMetadata pngMetadata = new PNGMetadata();
if (dpi != 96) {
pngMetadata.pHYs_present = true;
pngMetadata.pHYs_unitSpecifier = PNGMetadata.PHYS_UNIT_METER;
pngMetadata.pHYs_pixelsPerUnitXAxis = (int) Math.round(dpi / .0254 + 0.5);
pngMetadata.pHYs_pixelsPerUnitYAxis = pngMetadata.pHYs_pixelsPerUnitXAxis;
}
if (metadata != null) {
pngMetadata.zTXt_keyword.add("plantuml");
pngMetadata.zTXt_compressionMethod.add(new Integer(0));
pngMetadata.zTXt_text.add(metadata);
// Log.println("metadata=" + metadata);
// if (metadata.equals("Generated by
// http://plantuml.sourceforge.net")) {
// throw new IllegalArgumentException();
// }
}
if (debugData != null) {
pngMetadata.tEXt_keyword.add("debug");
pngMetadata.tEXt_text.add(debugData);
}
pngMetadata.tEXt_keyword.add("copyleft");
pngMetadata.tEXt_text.add(copyleft);
Log.debug("PngIOMetadata pngMetadata=" + pngMetadata);
// Render the PNG to file
final IIOImage iioImage = new IIOImage(image, null, pngMetadata);
Log.debug("PngIOMetadata iioImage=" + iioImage);
// Attach the metadata
final ImageWriter imagewriter = getImageWriter();
Log.debug("PngIOMetadata imagewriter=" + imagewriter);
synchronized (imagewriter) {
imagewriter.setOutput(ImageIO.createImageOutputStream(os));
imagewriter.write(null, iioImage, null);
os.flush();
imagewriter.reset();
imagewriter.dispose();
}
// Log.debug("PngIOMetadata before flush");
// os.flush();
// Log.debug("PngIOMetadata after flush");
}