本文整理汇总了Java中javax.imageio.ImageWriter.getDefaultImageMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java ImageWriter.getDefaultImageMetadata方法的具体用法?Java ImageWriter.getDefaultImageMetadata怎么用?Java ImageWriter.getDefaultImageMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageWriter
的用法示例。
在下文中一共展示了ImageWriter.getDefaultImageMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGif
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
/**
* Create the gif and clear down afterwards.
*
* @return the gif byte data
* @throws IOException if the output fails
*/
public byte[] createGif() throws IOException {
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(baos); // N.b. not try with closure because we need to close the stream before returning
ImageWriter iw = ImageIO.getImageWritersByFormatName("gif").next();
iw.setOutput(ios);
iw.prepareWriteSequence(null);
int index = 0;
ImageWriteParam iwp = iw.getDefaultWriteParam();
String frameDelay = String.valueOf(OptionsObject.getInstance().getGifDisplayTimeMillis() / 10L);
log.debug("Frames size: {}, Free memory {}", frames.size(), Runtime.getRuntime().freeMemory());
for (BufferedImage frame : frames) {
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(frame), iwp);
configureMetaData(metadata, frameDelay, index++);
iw.writeToSequence(new IIOImage(frame, null, metadata), null);
}
iw.endWriteSequence();
ios.close();
return baos.toByteArray();
} finally {
baos = null;
frames = null;
}
}
示例2: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String format = "javax_imageio_1.0";
BufferedImage img =
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
IIOMetadata meta =
iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
DOMImplementationRegistry registry;
registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
Document doc = impl.createDocument(null, format, null);
Element root, text, entry;
root = doc.getDocumentElement();
root.appendChild(text = doc.createElement("Text"));
text.appendChild(entry = doc.createElement("TextEntry"));
// keyword isn't #REQUIRED by the standard metadata format.
// However, it is required by the PNG format, so we include it here.
entry.setAttribute("keyword", "Comment");
entry.setAttribute("value", "Some demo comment");
meta.mergeTree(format, root);
}
示例3: writeImageWithHist
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
protected File writeImageWithHist(BufferedImage bi) throws IOException {
File f = File.createTempFile("hist_", ".png", new File("."));
ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
ImageTypeSpecifier type = new ImageTypeSpecifier(bi);
IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);
/* add hIST node to image metadata */
imgMetadata = upgradeMetadata(imgMetadata, bi);
IIOImage iio_img = new IIOImage(bi,
null, // no thumbnails
imgMetadata);
writer.write(iio_img);
ios.flush();
ios.close();
return f;
}
示例4: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) {
ImageWriter w = ImageIO.getImageWritersByFormatName(format).next();
if (w == null) {
throw new RuntimeException("No available writers for format " + format);
}
ImageWriteParam p = w.getDefaultWriteParam();
ImageTypeSpecifier t =
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata m = w.getDefaultImageMetadata(t, p);
System.out.println("Default image metadata is " + m);
testWritableMetadata(m);
IIOMetadata sm = w.getDefaultStreamMetadata(p);
System.out.println("Default stream metadata is " + sm);
testWritableMetadata(sm);
}
示例5: doTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void doTest(int mode) {
String fileFormat = "bmp";
try {
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix(fileFormat).next();
if(iw == null) {
throw new RuntimeException("No available image writer for "
+ fileFormat
+ " Test failed.");
}
File file = new File("image." + fileFormat);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
BufferedImage bimg = new BufferedImage(100,
100, BufferedImage.TYPE_INT_RGB);
Graphics g = bimg.getGraphics();
g.setColor(Color.green);
g.fillRect(0,0,100,100);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(mode);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg),
param);
IIOImage iioImg = new IIOImage(bimg, null, meta);
iw.write(null, iioImg, param);
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("Test failed.");
}
}
示例6: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IIOInvalidTreeException {
// getting the writer for the png format
Iterator iter = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) iter.next();
// creating a color model
ColorModel colorModel = ColorModel.getRGBdefault();
// creating a sample model
SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);
// creating a default metadata object
IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
String formatName = metaData.getNativeMetadataFormatName();
// first call
Node metaDataNode = metaData.getAsTree(formatName);
try {
metaData.setFromTree(formatName, metaDataNode);
} catch (Exception ex) {
ex.printStackTrace();
}
// second call (bitdepht is already set to an invalid value)
metaDataNode = metaData.getAsTree(formatName);
metaData.setFromTree(formatName, metaDataNode);
}
示例7: writeTo
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
try {
ImageOutputStream imageOutputStream =
ImageIO.createImageOutputStream(f);
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
imageWriter.setOutput(imageOutputStream);
IIOMetadata m =
imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
String format = m.getNativeMetadataFormatName();
Node root = m.getAsTree(format);
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
imageOutputStream.close();
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
示例8: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
ImageWriter iw =
(ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();
ImageTypeSpecifier type =
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
ImageOutputStream ios =
ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
iw.setOutput(ios);
IIOMetadata meta = iw.getDefaultImageMetadata(type, null);
boolean isFailed = false;
String[] fmts = meta.getMetadataFormatNames();
for (int i=0; i<fmts.length; i++) {
System.out.print("Format: " + fmts[i] + " ... ");
Node root = meta.getAsTree(fmts[i]);
try {
meta.mergeTree(fmts[i], root);
} catch (NullPointerException e) {
throw new RuntimeException("Test failed for format " + fmts[i], e);
}
System.out.println("PASSED");
}
}
示例9: doTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
protected void doTest() throws IOException {
BufferedImage biSrc = getSrc();
ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
ImageWriteParam writeParam = writer.getDefaultWriteParam();
IIOMetadata imageMetadata =
writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);
IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
writer.write(streamMetadata, iioImg, writeParam);
ios.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
BufferedImage dst = reader.read(0);
// do test
int x = dx / 2;
int y = height / 2;
for (int i = 0; i < usedColors.length; i++) {
int dstRgb = dst.getRGB(x, y);
System.out.println("dstColor: " + Integer.toHexString(dstRgb));
int srcRgb = usedColors[i].getRGB();
System.out.println("srcColor: " + Integer.toHexString(srcRgb));
if (dstRgb != srcRgb) {
throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
}
x += dx;
}
}
示例10: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
AnimationTest t = new AnimationTest();
t.initFrame();
ImageWriter w = t.initWriter();
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata streamMetadata = w.getDefaultStreamMetadata(p);
w.prepareWriteSequence(streamMetadata);
for (int i = 0; i < 50; i++) {
BufferedImage f = t.createNextFrame();
ImageTypeSpecifier type = new ImageTypeSpecifier(f);
IIOMetadata m = w.getDefaultImageMetadata(type, p);
w.writeToSequence(new IIOImage(f, null, m), p);
}
w.endWriteSequence();
t.checkAnimation();
} catch (Exception e) {
throw new RuntimeException("Test failed.", e);
}
}
示例11: writeTo
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
try (ImageOutputStream imageOutputStream =
ImageIO.createImageOutputStream(f)) {
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
imageWriter.setOutput(imageOutputStream);
IIOMetadata m =
imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
String format = m.getNativeMetadataFormatName();
Node root = m.getAsTree(format);
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
示例12: test
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void test(String mimeType, boolean useStreamMeta,
String metaXml, String... boolXpaths)
throws Exception
{
BufferedImage img =
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
iw.setOutput(ios);
ImageWriteParam param = null;
IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
IIOMetadata imageMeta =
iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
Source src = new StreamSource(new StringReader(metaXml));
DOMResult dst = new DOMResult();
transform(src, dst);
Document doc = (Document)dst.getNode();
Element node = doc.getDocumentElement();
String metaFormat = node.getNodeName();
// Verify that the default metadata gets formatted correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, false);
meta.mergeTree(metaFormat, node);
// Verify that the merged metadata gets formatte correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, true);
iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
iw.dispose();
ios.close();
ImageReader ir = ImageIO.getImageReader(iw);
byte[] bytes = os.toByteArray();
if (bytes.length == 0)
throw new AssertionError("Zero length image file");
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
ir.setInput(iis);
if (useStreamMeta) meta = ir.getStreamMetadata();
else meta = ir.getImageMetadata(0);
// Verify again after writing and re-reading the image
verify(meta.getAsTree(metaFormat), boolXpaths, true);
}
示例13: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String format = "GIF";
ImageWriter writer =
ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No available writers for " + format);
}
BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
ImageWriteParam p = writer.getDefaultWriteParam();
ImageTypeSpecifier type =
ImageTypeSpecifier.createFromRenderedImage(img);
IIOMetadata inImageMetadata =
writer.getDefaultImageMetadata(type, p);
IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);
// write and read image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);
ios.flush();
ios.close();
// read result
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
IIOMetadata outStreamMetadata = reader.getStreamMetadata();
GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;
if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
throw new RuntimeException("Test failed due to wrong logical screen dimension.");
}
}
示例14: WbmpDefaultImageMetadataTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public WbmpDefaultImageMetadataTest(String format) {
try {
bimg = new BufferedImage(200, 200, bimg.TYPE_INT_RGB);
Graphics gg = bimg.getGraphics();
gg.setColor(Color.red);
gg.fillRect(50, 50, 100, 100);
Iterator it = ImageIO.getImageWritersByFormatName(format);
if (it.hasNext()) {
writer = (ImageWriter) it.next();
}
if (writer == null) {
throw new RuntimeException("No writer available for the given format."
+ " Test failed.");
}
writeParam = writer.getDefaultWriteParam();
System.out.println("Testing Image Metadata for "+format+"\n");
imageData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), writeParam);
if (imageData == null) {
System.out.println("return value is null. No default image metadata is associated with "+format+" writer");
throw new RuntimeException("Default image metadata is null."
+ " Test failed.");
}
int j = 0;
String imageDataNames[] = null;
if(imageData != null) {
System.out.println("Is standard metadata format supported (Image) ? "+
imageData.isStandardMetadataFormatSupported() );
imageDataNames = imageData.getMetadataFormatNames();
System.out.println("\nAll supported Metadata Format Names\n");
if(imageDataNames!=null){
for(j=0; j<imageDataNames.length; j++) {
System.out.println("FORMAT NAME: "+imageDataNames[j]);
if (imageDataNames[j].equals(imageData.getNativeMetadataFormatName())) {
System.out.println("This is a Native Metadata format\n");
} else {
System.out.println("\n");
}
System.out.println("");
System.out.println("IIOImageMetadata DOM tree for "+imageDataNames[j]);
System.out.println("");
Node imageNode = imageData.getAsTree(imageDataNames[j]);
displayMetadata(imageNode);
System.out.println("\n\n");
}
}
}
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException("Exception was thrown."
+ " Test failed.");
}
}
示例15: BmpDefaultImageMetadataTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public BmpDefaultImageMetadataTest(String format) {
try {
bimg = new BufferedImage(200, 200, bimg.TYPE_INT_RGB);
Graphics gg = bimg.getGraphics();
gg.setColor(Color.red);
gg.fillRect(50, 50, 100, 100);
Iterator it = ImageIO.getImageWritersByFormatName(format);
if (it.hasNext()) {
writer = (ImageWriter) it.next();
}
if (writer == null) {
throw new RuntimeException("No writer available for the given format."
+ " Test failed.");
}
writeParam = writer.getDefaultWriteParam();
System.out.println("Testing Image Metadata for "+format+"\n");
imageData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), writeParam);
if (imageData == null) {
System.out.println("return value is null. No default image metadata is associated with "+format+" writer");
throw new RuntimeException("Default image metadata is null."
+ " Test failed.");
}
int j = 0;
String imageDataNames[] = null;
if(imageData != null) {
System.out.println("Is standard metadata format supported (Image) ? "+
imageData.isStandardMetadataFormatSupported() );
imageDataNames = imageData.getMetadataFormatNames();
System.out.println("\nAll supported Metadata Format Names\n");
if(imageDataNames!=null){
for(j=0; j<imageDataNames.length; j++) {
System.out.println("FORMAT NAME: "+imageDataNames[j]);
if (imageDataNames[j].equals(imageData.getNativeMetadataFormatName())) {
System.out.println("This is a Native Metadata format\n");
} else {
System.out.println("\n");
}
System.out.println("");
System.out.println("IIOImageMetadata DOM tree for "+imageDataNames[j]);
System.out.println("");
Node imageNode = imageData.getAsTree(imageDataNames[j]);
displayMetadata(imageNode);
System.out.println("\n\n");
}
}
}
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException("Exception was thrown."
+ " Test failed.");
}
}