-2

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
maddy
  • 109
  • 4
  • 13

1 Answers1

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