I guess this one is rather simple for those who use GDI more frequently. I have an image that I want to rotate.
Sample image:
After I apply my rotation, it looks like the following:
Here's the code used:
public Bitmap RotateBitmap(Bitmap bitmap, float angle)
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
graphics.DrawImage(bitmap, new Point(0, 0));
}
return bitmap;
}
What I want to get rid of is the part of the image that remains there from before the rotation. Any attempts to use DrawRectangle
and Clear
before calling DrawImage
gave me white images, which makes some kind of sense.