Win a copy of Raising Young Coders: A Parent’s Guide to Teaching Programming at Home this week in the General Computing forum!
Forums Login/signup

Backwards image rotation

+Pie Number of slices to send: Send
Hi all! I am writing an image rotating algorithm. I have the code to actually rotate the image, which works fine;



But the rotated image has 'holes' or missing pixels. I do understand why this happens. But here comes the problem; For the missing pixel coordinates, I need to do the calculation backwards to find out where that pixel would be in the original non-rotated image so I can bilinear interpolate to find out what the color should be. But my maths are really failing me on this part. How do I write this algorithm backwards?
2
+Pie Number of slices to send: Send
You aren't writing the algorithm, but code to go with it. Have you tried applying affine transforms to the Graphics object? You would want something like thisIt will be easier to understand the process if you move the “centre” of the graphics to the centre of your panel with the translate() method first.
I can't remember the correct algorithm, but it involves a matrix multiplication; you can find more details either in the rotate() method or in the AffineTransform class. It would take me a few hours with my Maths book to get up to speed with matrices again.

reply
reply
This thread has been viewed 360 times.
Similar Threads
saving transformed images
Horizontal flip
Describe the class representing the triangle
How to create the movement by Using 10 pixels as the length of each movement?
Code to print , rotate, zoom an image from an applet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 27, 2025 01:18:42.