how to we add bitmap image in panel and then get the graphics that the image is using and tell the panel to draw a line using the same graphics inside the image.
Asked
Active
Viewed 193 times
-2
-
1You want to edit the image? Maybe save the results? – MadProgrammer Dec 08 '12 at 06:09
-
no nothing of that sort..jst want to do the above mentioned thing – maddy Dec 08 '12 at 08:42
-
See [this answer](http://stackoverflow.com/questions/12683533/drawing-a-rectangle-that-wont-disappear-in-next-paint/12683632#12683632) for a starting point (although it is a bit long). – Andrew Thompson Dec 08 '12 at 22:12
-
i was new to this site..atleast ppl shud comment before closing questions – maddy Dec 10 '12 at 10:56
1 Answers
2
Basic painting is done by a Swing components paintComponent
method.
The best choice you have is to load the image using the ImageIO
API...
BufferedImage image;
public void loadImage() throws IOException {
image = ImageIO.read(...);
// ImageIO can read a image from a file or a URL or a ImageInputStream
}
Then simply paint the image...
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
// Now you can continue drawing ontop of it...
g.setColor(Color.RED);
g.drawLine(0, 0, image.getWidth(), image.getHeight());
}
You might like to have a read of

MadProgrammer
- 343,457
- 22
- 230
- 366