日期:2014-05-20 浏览次数:20851 次
Image image3=image2.getImage(); BufferedImage bufImg = new BufferedImage(image3.getWidth(null), image3.getHeight(null), BufferedImage.TYPE_INT_RGB); bufImg.getGraphics().drawImage(image3, 0, 0, null); FileOutputStream fos; try { fos = new FileOutputStream( "D://javaChat/01.jpg"); com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(fos); encoder.encode(bufImg); fos.close(); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace();} catch(Exception ett){ ett.printStackTrace(); }
ImageIO.write(b, "GIF", new FileOutputStream("c:\\a.gif"));
------解决方案--------------------
BufferedImage bufImg = new BufferedImage(image3.getWidth(null), image3.getHeight(null), BufferedImage.TYPE_INT_RGB);
bufImg.getGraphics().drawImage(image3, 0, 0, null);
ImageIO.write(bufImg, "GIF", new FileOutputStream("c:\\a.gif"));