📄 apps.fm4.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><title>Java Image I/O API Guide: 3 - Writing Image I/O Applications</title></head><body bgcolor="#ffffff"> <table summary="layout" width="100%"><tr><td><!-- Bug in Communicator w/font: NavBar text disappears for Times 14pt pref. --><!-- font size="-1" --> <a href="imageio_guideTOC.fm.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html">CONTENTS</a> | <a href="apps.fm3.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/apps.fm3.html">PREV</a> | <a href="apps.fm5.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/apps.fm5.html">NEXT</a> <!-- | <a href="copyright.fm.html">INDEX</a> --><!-- /font --></td><td align=right><i>Java<sup><font size="-1">TM</font></sup></font> Image I/O API Guide</i></td></tr></table><br> <p><hr size="8" width="35%" align="left" noshade><h2><a name="996927"><i>3.4 </i> The <code>ImageWriter</code> Class</a></h2><blockquote><a name="997001"><!-- --></a>Just as we obtained a list of <code>ImageReader</code>s for a particular format using a method from the <code>ImageIO</code> class, we can obtain a list of <code>ImageWriter</code>s:<p></blockquote><blockquote><pre>Iterator writers = ImageIO.getImageWritersByFormatName("png");ImageWriter writer = (ImageWriter)writers.next();</pre></blockquote><blockquote><a name="997034"><!-- --></a>Once an <code>ImageWriter</code> has been obtained, its destination must be set to an <code>ImageOutputStream</code>:<p></blockquote><blockquote><pre>File f = new File("c:\images\myimage.png");ImageOutputStream ios = ImageIO.createImageOutputStream(f);writer.setOutput(ios);</pre></blockquote><blockquote><a name="997041"><!-- --></a>Finally, the image may be written to the output stream:<p></blockquote><blockquote><pre>BufferedImage bi;writer.write(bi);</pre></blockquote><br><h3><a name="997015"><!-- --></a><i>3.4.1 </i> Writing Multiple Images</h3><blockquote><a name="997103"><!-- --></a>The <code>IIOImage</code> class is use to store references to an image, one or more thumbnail images, and metadata (non-image data) associated with the image. Metadata will be discussed below; for now, we will simply pass <code>null</code> as the value for the metadata-related parameters.<p><a name="997148"><!-- --></a>The <code>ImageWriter</code> class contains a <code>write</code> method that creates a new file from an <code>IIOImage</code>, and a <code>writeInsert</code> method that adds an <code>IIOImage</code> to an existing file . By calling the two in sequence a multi-image file may be written:<p></blockquote><blockquote><pre>BufferedImage first_bi, second_bi;IIOImage first_IIOImage = new IIOImage(first_bi, null, null);IIOImage second_IIOImage = new IIOImage(second_bi, null, null);writer.write(null, first_IIOImage, null);if (writer.canInsertImage(1)) { writer.writeInsert(1, second_IIOImage, null);} else { System.err.println("Writer can't append a second image!");}</pre></blockquote><br><hr><!-- Bug in Communicator w/font: NavBar text disappears for Times 14pt pref. --><!-- font size="-1" --> <a href="imageio_guideTOC.fm.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html">CONTENTS</a> | <a href="apps.fm3.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/apps.fm3.html">PREV</a> | <a href="apps.fm5.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/apps.fm5.html">NEXT</a> <!-- | <a href="copyright.fm.html">INDEX</a> --><!-- /font --><hr><font size="-1"><i><A HREF="copyright.fm.html" tppabs="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/copyright.fm.html">Copyright</a> © 2001 Sun Microsystems, Inc. All Rights Reserved.</i></font><!-- This HTML file was created with Quadralay WebWorks Publisher 3.5.0 --><!-- by Suzette Pelouch --><!-- Last updated: Fri Apr 27 11:22:59 2001 --> </body><script language="JavaScript" src="s_code_remote.js" tppabs="http://java.sun.com/js/omi/jsc/s_code_remote.js"></script></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -