Topic: 新问题:如何保存一幅图片?

  Print this page

1.新问题:如何保存一幅图片? Copy to clipboard
Posted by: mylihang
Posted on: 2004-11-04 19:35

请问,如何保存显示在JPanel中的图片啊?
我使用paint()方法逐点draw上了一幅图片(原来的格式是数字矩阵),现在我想把显示出来的图片保存成真正的图片,请问我该使用什么方法啊?
急,请高手解答,谢谢!!!

2.Re:新问题:如何保存一幅图片? [Re: mylihang] Copy to clipboard
Posted by: wkb750214
Posted on: 2004-11-08 14:42

up

3.Re:新问题:如何保存一幅图片? [Re: mylihang] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-11-09 17:27

这种情况我也不知道

4.Re:新问题:如何保存一幅图片? [Re: mylihang] Copy to clipboard
Posted by: jameszhang
Posted on: 2004-11-10 08:16

如果你保存图象应该用javax.imageio.ImageIO

5.Re:新问题:如何保存一幅图片? [Re: mylihang] Copy to clipboard
Posted by: yy00_789
Posted on: 2004-11-25 14:32

用外部包!如JClass等提供此功能!

6.Re:新问题:如何保存一幅图片? [Re: mylihang] Copy to clipboard
Posted by: icefans
Posted on: 2004-11-28 18:00

(转载)

public void saveComponentToJPEG(Component c,String fileName ) {
try {
int w=c.getWidth();
int h=c.getHeight();
java.awt.image.BufferedImage image=(java.awt.image.BufferedImage)c.createImage(w,h);
Graphics2D g2=image.createGraphics();
c.print(g2);
BufferedOutputStream bos =
new BufferedOutputStream( new FileOutputStream( fileName ));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( bos );
JPEGEncodeParam jep = encoder.getDefaultJPEGEncodeParam(image);
jep.setQuality( 1.0f, false );
encoder.setJPEGEncodeParam( jep );
encoder.encode( image );
bos.close();
JOptionPane.showMessageDialog(gm,fileName+"保存成功!");
}
catch ( Exception e ) {
e.printStackTrace();
}
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923