Search code examples
javaimageswinggraphics2d

Graphics2D draw image inside of defined quadrilateral


I cannot find a draw image overload inside of Graphics2D which will enable me to perform such a task, can someone help me figure out how one might do this - preferably without swapping to more advanced graphics frameworks such as OpenGl,

thanks.

To clarify, a quad can be defined by anything with four-sides; that means a diamond or a rectangle or more elaborate shapes.

Mre has removed many of his remarks and so It seems as though I am responding to no-one, however all I have said in the comments were responses to what mre had said.


Solution

  • See Andrew Thomson's solution for the basics.

    Instead of using a "text shape", I created a Shape using:

    Polygon polygon = new Polygon();
    polygon.addPoint(250, 50);
    polygon.addPoint(350, 50);
    polygon.addPoint(450, 150);
    polygon.addPoint(350, 150);
    g.setClip(polygon);
    g.drawImage(originalImage, 0, 0, null);