Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

save image

 
vijayalakshmi sundararajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have written a program that will draw a line.
I want a save button which would help me to save the picture in GIF or JPG format.
the program that I hv written to draw the lines is as below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Lines extends JFrame
{
private String s = (" Using javaStrings ");
public Lines()
{
super(" Drawing Lines ");
setSize(500,165);
show();
}
public void paint( Graphics g)
{
g.setColor(Color.blue);
g.fillRect(20,120,50,5);
g.setColor(Color.blue);
g.fillRect(100,120,50,5);
g.setColor(Color.blue);
g.fillRect(170,120,50,5);
g.setColor(Color.blue);
g.fillRect(240,120,50,5);
g.setColor(Color.blue);
g.fillRect(300,120,50,5);
g.setColor(Color.green);
g.fillRect(70,100,30,5);
g.setColor(Color.green);
g.fillRect(150,100,20,5);
g.setColor(Color.green);
g.fillRect(220,100,20,5);
g.setColor(Color.green);
g.fillRect(290,100,10,5);
g.setColor(Color.red);
g.fillRect(20,150,350,5);

}
public static void main(String[] args)
{
Lines app= new Lines();
app.addWindowListener( new WindowAdapter ()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
Kindly help me out in saving the image that is been displayed after running this program.
Regards,
Vijju
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Vijju.
I have modified you program to write to a file Lines.jpg
I do not know if it is the best way.
The example uses com.sun.image.codec.jpeg clases, for which there is no API. You can look at the source code by something like jar -tvf c:\j2sdk1.4.2_01\src.zip com/sun/image/codec/jpeg

[ December 08, 2003: Message edited by: Jose Botella ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic