3

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?

julien
  • 898
  • 3
  • 17
  • 32

2 Answers2

1

You'll find code for how to do it in objective-c here https://github.com/hfossli/AGGeometryKit/ . I'm sure it is possible to port to java.

hfossli
  • 22,616
  • 10
  • 116
  • 130
  • Thanks. I'll try to port it into java. – julien Mar 15 '13 at 15:00
  • Ok, cool. The only thing your really need is the code found here: http://stackoverflow.com/a/12820877/202451 . You should be able to create a 3d matrix for java with that code. It is the same code as found at the bottom of this file https://github.com/hfossli/AGGeometryKit/blob/master/Source/AGQuad.m – hfossli Mar 15 '13 at 17:47
  • You need a matrix with 4 rows and columns... I don't think this will do http://developer.android.com/reference/android/graphics/Matrix.html – hfossli Mar 15 '13 at 17:49
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

aoi222
  • 723
  • 1
  • 5
  • 11