-1

I want to make rectangles on a JLabel and the convert that rectangle into a BufferedImage... like layers in paint shop... drage that BufferedImage and resize...can anyone help

I have done this but it didnt work

Rectangle2D rectangle2D;
                            BufferedImage bi = new BufferedImage(bimg.getWidth(), bimg.getHeight(), BufferedImage.TYPE_INT_RGB);
                            Graphics2D big = bi.createGraphics();
                            rectangle2D = new Rectangle2D.Float(eX, eY, sW, sH);
                            big.setStroke(new BasicStroke(5));
                            big.setColor(color);
                            shapePaint = new TexturePaint(bi, rectangle2D);
                            g2d.setPaint(shapePaint);
Complicated
  • 117
  • 2
  • 16

1 Answers1

5

I want to make rectangles on a JLabel and the convert that rectangle into a BufferedImage

You are doing it the wrong way around. Draw to the buffered image, add it to a label, call label.repaint() to display any changes.

E.G.

As seen in..

  1. This answer
  2. This answer

  3. This answer or..
  4. ..For an animated version, this answer
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433