0

I know that one can use g2d.setPaint(new TexturePaint(img,rect)) in order to fill a shape with an Image, but the problem is that the shape is tessellated with the image instead of rescaling the single image to the bounding box of the shape in order to fill the whole area. The latter is what I want to achieve.

For example, if I have an image of 20x20 and I want to fill an Ellipse2D of width = 200 and height = 300, I would like to fill that Ellipse2D with a rescaled version of 200x300 of the image instead of tessellating it with the 20x20 image.

Is there a way to achieve this and hopefully in an efficient way?

Aleksandr Podkutin
  • 2,532
  • 1
  • 20
  • 31
Pablo Messina
  • 431
  • 1
  • 3
  • 13

1 Answers1

0

Try this:

g2d.setPaint(new TexturePaint(img.getScaledInstance(200, 300, 0),rect));

I never tried this out before but it seems like it should work.

Mmir
  • 357
  • 3
  • 10