1)自己用java实现所有的编码,但要熟悉图像文件的格式2)使用现有的图形库,例如jmagick

解决方案 »

  1.   

    在现在的jdk中早已能支持常用的一些图象格式,如jpg,png,gif等
    用javax.imageio.ImageIO类中的write(RenderedImage im, String formatName, File output) 
              方法就可以将RenderedImage对象写入指定格式的文件中,
    现在的难点就是不知道该怎样把image对象转换为RenderedImage接口的实现类如BufferedImage
      

  2.   

    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);
        }