How to store Images(gif/jpeg) created in the java program?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shridhar_N
Posted On:   Wednesday, September 12, 2001 12:05 AM

Hello I have a image and on that image i will write a text and now i want to store the new image file . How to do this.? I am using the following code for that, Canvas c=new Canvas(); Toolkit toolkit = Toolkit.getDefaultToolkit(); java.awt.Image image = toolkit.getImage("hi.gif"); g.drawImage(image, 0, 0,this); g.setColor(Color.blue); g.drawString("Hello !!", 60, 20); Till this it will draw the image and write a text on that image ,,Now i want to store this new image file .. How to do this? If you have the sample code for that please do send me that.. Thanks for your time.. Shridhar..    More>>

Hello

I have a image and on that image i will write a text and now i want to store the new image file . How to do this.?
I am using the following code for that,

Canvas c=new Canvas();
Toolkit toolkit = Toolkit.getDefaultToolkit();
java.awt.Image image = toolkit.getImage("hi.gif");
g.drawImage(image, 0, 0,this);
g.setColor(Color.blue);
g.drawString("Hello !!", 60, 20);

Till this it will draw the image and write a text on that image ,,Now i want to store this new image file .. How to do this? If you have the sample code for that please do send me that..

Thanks for your time..

Shridhar..

   <<Less

Re: How to store Images(gif/jpeg) created in the java program?

Posted By:   Rob_Derr  
Posted On:   Friday, September 14, 2001 01:01 PM

Here is the implementation of a write() method...
the encoder is in com.sun.image.codec.jpeg

/**
* write a java.awt.image.BufferedImage to a file
* Creation date: (2/14/2001 10:52:00 AM)
*/
public void write()
{
//
BufferedOutputStream bos= null;
FileOutputStream fos= null;
//

try
{
//
fos= new FileOutputStream(this.getPath() + this.getName());
bos= new BufferedOutputStream(fos);
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(bos);
//

//
encoder.encode(this.getImage());
//

}
//
catch (Exception e)
{
System.out.println(e);
}
//

//
finally
{
try
{
if (!(bos == null))
{
bos.close();
}
if (!(fos == null))
{
fos.close();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
//

}
About | Sitemap | Contact