Image Shape Manipulation

I’m trying to figure out how to take a square image and transform it into a different quadrilateral. Basically get from a rectangular image with 4 90 degree angles to a quadrilateral with one 90, one 30, one 110, and one 130 degree angle. Is that possible in Java and how can I do this?

Thanks Rowdy.

I’m not aware of a simple way to do it with java.awt.* classes. Unfortunately that’s not an affine transform. You’d have to write code to loop through the pixels of the quadrilateral computing texture coordinates and then extracting the appropriate colour from your image.

Alternatively it’s pretty trivial with one of the OpenGL bindings - just a quad with your image as a texture.

Thanks for your help, and that’s what I was afraid of… I didn’t think you easily could.

Rowdy

Quick question: is the input image always going to be the same size, and the output shape always going to be the same? If so then there’s a cheating way of doing it by preparing an offline mapping.

Basically you set up a texture with a column of 0x000000, then a column of 0x000004, etc. Render it with JOGL with antialiasing disabled and dump to file. Repeat with horizontal rather than vertical lines. The colour values in the files can be processed into sub-pixel texture coordinates (to the quarter-pixel) which you can then apply to an arbitrary image. If you want antialiased edges then you repeat with a texture of full-white on a full-black background to get the alpha channel.