Friday, January 13, 2012

Drawing/warping a rectangular image into a quadrilateral image


I need to draw a BufferedImage within a given quadrilateral. I want to do that:



enter image description here



I would like the cat to be deformed to be drawn within the quadrilateral.



Graphics objects have different methods to draw images, but only to stretch them along the X and Y axis (See Graphics.drawImage methods).



What I am dreaming of is a method Graphics.drawImage() where I specify the coordinates of the 4 quadrilateral points. Is there an easy way to do that?

1 comment:

  1. I don't know of any easy way to do this with the standard java packages. You could of course implement your own Bilinear or Perspective transform for four corner image warping, but who wants to do all that work.

    I think your best bet is to look into the Java Advanced Imaging API (javax.media.JAI). Here is an article that talks about perspective transforms with JAI: http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Geom-image-manip.doc.html#55959

    ReplyDelete