Jump to content
  • Advertisement
Sign in to follow this  
TeSsL

Rotating images

This topic is 3170 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

hihi i am testing out this code. But the problem is how come the result image is also scaled on top of the rotation? How should i change it so that the size of the input image is unchanged?
private Bitmap rotateImage(Bitmap b, float angle)
{
  //create a new empty bitmap to hold rotated image
  Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
  //make a graphics object from the empty bitmap
  Graphics g = Graphics.FromImage(returnBitmap);
  //move rotation point to center of image
  g.TranslateTransform((float)b.Width/2, (float)b.Height / 2);
  //rotate
  g.RotateTransform(angle);
  //move image back
  g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
  //draw passed in image onto graphics object
  g.DrawImage(b, new Point(0, 0)); 
  return returnBitmap;
}

Share this post


Link to post
Share on other sites
Advertisement
Are you sure the problem is scaling, or is it that the result doesn't fit in the rectangle? Can you post sample input and output images to show us what you are getting?

Share this post


Link to post
Share on other sites
Somehow it happens at random.. some scales down and some up.. I really don't understands y..
this is it: Photobucket
Hope u can help.. Thx:)

Share this post


Link to post
Share on other sites
I can't see where the scaling is coming from, but I'm not familiar with C#. What The only fishy thing I see in your code is that the two translations seem to be swapped. But perhaps I'm missing something.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!