Jump to content
  • Advertisement
Sign in to follow this  
AndyTang

Image Rotation Problems

This topic is 3168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!