Image Rotation Problems

Started by
3 comments, last by AndyTang 14 years, 6 months ago
I've recently tried rotating a alpha-transparent PNG but have run into a few snag and hope you guys can help. Basically, all I'm doing is going through every pixel in the source bitmap, rotating it, and placing it on the destination bitmap in the new position. The image rotates great but the images have gaps and holes. Is there a technique I should be using?
Advertisement
Yes, you should loop through the destination pixels instead. For each one of them, find out where they come from in the original image, apply some interpolation if need be and then populate it. You'll get no ugly artifacts if you do it this way.

Thanks for the quick reply! I have the formula to go from source to destination:
x' = x * cos(a) + y * sin(a) + cx
y' = y * cos(a) - x * sin(a) + cy

Is it a matter of just using the same formula in reverse, or is there a clever way to work out the source destination? I'm actually quite surprise there isn't something in GDI or GDI+ that does both alpha transparencies and rotation.
Quote:Original post by Chrominium
Thanks for the quick reply! I have the formula to go from source to destination:
x' = x * cos(a) + y * sin(a) + cx
y' = y * cos(a) - x * sin(a) + cy


The inverse of that transformation is

x = (x' - cx) * cos(a) - (y' - cy) * sin(a)
y = (y' - cy) * cos(a) + (x' - cx) * sin(a)

But please, check my Math.
Thanks for your reply. I will check it :)

This topic is closed to new replies.

Advertisement