ImageIO /** * Returns a <code>BufferedImage</code> as the result of decoding * a supplied <code>InputStream</code> with an <code>ImageReader</code> * chosen automatically from among those currently registered. * The <code>InputStream</code> is wrapped in an * <code>ImageInputStream</code>. If no registered * <code>ImageReader</code> claims to be able to read the * resulting stream, <code>null</code> is returned. * * <p> The current cache settings from <code>getUseCache</code>and * <code>getCacheDirectory</code> will be used to control caching in the * <code>ImageInputStream</code> that is created. * * <p> This methods does not attempt to locate * <code>ImageReader</code>s that can read directly from an * <code>InputStream</code>; that may be accomplished using * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. * * @param input an <code>InputStream</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded * contents of the input, or <code>null</code>. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */ public static BufferedImage read(InputStream input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); } ImageInputStream stream = createImageInputStream(input); return read(stream); }
用javax.imageio.ImageIO类中的write(RenderedImage im, String formatName, File output)
方法就可以将RenderedImage对象写入指定格式的文件中,
现在的难点就是不知道该怎样把image对象转换为RenderedImage接口的实现类如BufferedImage
* Returns a <code>BufferedImage</code> as the result of decoding
* a supplied <code>InputStream</code> with an <code>ImageReader</code>
* chosen automatically from among those currently registered.
* The <code>InputStream</code> is wrapped in an
* <code>ImageInputStream</code>. If no registered
* <code>ImageReader</code> claims to be able to read the
* resulting stream, <code>null</code> is returned.
*
* <p> The current cache settings from <code>getUseCache</code>and
* <code>getCacheDirectory</code> will be used to control caching in the
* <code>ImageInputStream</code> that is created.
*
* <p> This methods does not attempt to locate
* <code>ImageReader</code>s that can read directly from an
* <code>InputStream</code>; that may be accomplished using
* <code>IIORegistry</code> and <code>ImageReaderSpi</code>.
*
* @param input an <code>InputStream</code> to read from.
*
* @return a <code>BufferedImage</code> containing the decoded
* contents of the input, or <code>null</code>.
*
* @exception IllegalArgumentException if <code>input</code> is
* <code>null</code>.
* @exception IOException if an error occurs during reading.
*/
public static BufferedImage read(InputStream input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("input == null!");
} ImageInputStream stream = createImageInputStream(input);
return read(stream);
}