Alex Rivera | Logout

How can I edit a jpg image through Java?

Asked 2009-06-17T21:29:38.737
15

I have loaded a jpg image in which I want to draw letters and circles, given a x,y coordinate.

I have been trying to figure out the paintIcon of the ImageIcon class

public void paintIcon(Component c,
                      Graphics g,
                      int x,
                      int y)

Does this method allow me to edit jpg images the way I want to? What are supposd to be the Component c and Graphics g paramethers? What would I add to its body to paint circles or letters?

I'm working on Netbeans 6.5, do I have anything builtin for this task (instead of ImageIcon)?

Edit
Report

1 Answer

18

The pure-Java way is to use ImageIO to load the image as a BufferedImage. Then you can call createGraphics() to get a Graphics2D object; you can then draw whatever you want onto the image.

You can use an ImageIcon embedded in a JLabel to do the displaying, and you can add a MouseListener and/or a MouseMotionListener to the JLabel if you're trying to allow the user to edit the image.

answered 2009-06-17T21:43:46.307

Your Answer