I want to use the 2D Java API to draw on a JLabel that already has an image on it and then save the resulting edited picture.
I can't find any tutorials on this specific subject, does anyone have any code or references that show how to do it?
I want to use the 2D Java API to draw on a JLabel that already has an image on it and then save the resulting edited picture.
I can't find any tutorials on this specific subject, does anyone have any code or references that show how to do it?
override the paintComponent
method of the JLabel
. It should first call super.paintComponent
, so you get whatever the JLabel
contains, then add your own drawing code after that. Should look somewhat like this:
public void paintComponent(Graphics g){
super.paintComponent(g)
g.drawWhatever ...
}
One approach would be to render the existing image and drawing into a BufferedImage
, as shown in this example that overlays text on a logo. Once the image is complete, use ImageIO.write()
to save it in the desired format.