bufferedimage 转换成 inputstream

BufferedImage imgBar = 。。。。。。;
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ImageOutputStream imOut = ImageIO.createImageOutputStream(bs);
ImageIO.write(imgBar, "jpg", imOut);
InputStream is = new ByteArrayInputStream(bs.toByteArray());




使用ImageIo时,发现图片失贞。

BufferedImage img = chart.createBufferedImage(600, 300,5, null);

createBufferedImage时加上一个参数5即可。

   /**
     * Represents an image with 8-bit RGB color components, corresponding
     * to a Windows-style BGR color model) with the colors Blue, Green,
     * and Red stored in 3 bytes.  There is no alpha.  The image has a
     * ComponentColorModel.
     * When data with non-opaque alpha is stored
     * in an image of this type,
     * the color data must be adjusted to a non-premultiplied form
     * and the alpha discarded,
     * as described in the
     * {@link java.awt.AlphaComposite} documentation.
     */
    public static final int TYPE_3BYTE_BGR = 5;


参考:

http://stackoverflow.com/questions/4386446/problem-using-imageio-write-jpg-file

你可能感兴趣的:(Java)