Public Group

Rotating images

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

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 on other sites
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 on other sites
Somehow it happens at random.. some scales down and some up.. I really don't understands y..
this is it:
Hope u can help.. Thx:)

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.

• 17
• 11
• 12
• 9
• 49
• Forum Statistics

• Total Topics
631394
• Total Posts
2999755
×