当前位置: 技术问答>java相关
求助一下现场观众:如何临时保存所绘制的图像,然后再需要时提取出来。
来源: 互联网 发布时间:2015-02-14
本文导语: 我系菜鸟,各位请了,我想把在程序中绘制的图像临时保存起来(不需要保存到磁盘),到需要时再取出绘制到别的地方,怎么办?或者说,java中有没有像vc中的cbitmap之类的东东可用。 | Sav...
我系菜鸟,各位请了,我想把在程序中绘制的图像临时保存起来(不需要保存到磁盘),到需要时再取出绘制到别的地方,怎么办?或者说,java中有没有像vc中的cbitmap之类的东东可用。
|
Save an Image as a GIF or JPEG file
Take a look at the following package :
http://www.obrador.com/essentialjpeg/jpeg.htm for JPEG
http://www.acme.com for GIF
http://rsb.info.nih.gov/ij/ can display BMP and save as GIF or TIFF
With JDK1.2, Sun introduces a new package called JIMI (available for download at their Web site. With this package, it's easy to convert a Java Image to a JPEG image file. double w = 200.0;
double h = 200.0;
BufferedImage image = new BufferedImage(
(int)w,(int)h,BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)image.getGraphics();
g.drawLine(0,0,w,h);
try {
File f = new File("myimage.jpg");
JimiRasterImage jrf = Jimi.createRasterImage(image.getSource());
Jimi.putImage("image/jpeg",jrf,new FileOutputStream(f));
}
catch (JimiException je) {je.printStackTrace();}
Take a look at the following package :
http://www.obrador.com/essentialjpeg/jpeg.htm for JPEG
http://www.acme.com for GIF
http://rsb.info.nih.gov/ij/ can display BMP and save as GIF or TIFF
With JDK1.2, Sun introduces a new package called JIMI (available for download at their Web site. With this package, it's easy to convert a Java Image to a JPEG image file. double w = 200.0;
double h = 200.0;
BufferedImage image = new BufferedImage(
(int)w,(int)h,BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)image.getGraphics();
g.drawLine(0,0,w,h);
try {
File f = new File("myimage.jpg");
JimiRasterImage jrf = Jimi.createRasterImage(image.getSource());
Jimi.putImage("image/jpeg",jrf,new FileOutputStream(f));
}
catch (JimiException je) {je.printStackTrace();}
|
可以用java.awt.image.BufferedImage类,它里边提供了很多的函数,它和vc中的CBitmap类差不多。
|
可以用MemoryImageSource类。