图像不能在中心周围完美旋转

时间:2014-12-15 14:03:10

标签: c# image-rotation

所以我有一个背景图片大小为123x123像素的图片框。

每次点击图像时,我都会使用下面的功能旋转一定的角度。

//The original image to rotate.
private readonly Bitmap _origPowerKnob = Properties.Resources.PowerKnob;

//Calling the rotation function.
using (Bitmap b = new Bitmap(_origPowerKnob))
{
    Bitmap newBmp = RotateImage(b, _powerAngle);
    PowerKnob.BackgroundImage = newBmp;
}

//Do the rotation.
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.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.TranslateTransform(b.Width / 2F, b.Height / 2F);
    //Rotate.
    g.RotateTransform(angle);
    //Move image back.
    g.TranslateTransform(-b.Width / 2F, -b.Height / 2F);
    //Draw passed in image onto graphics object.
    g.DrawImage(b, new PointF(0,0));
    return returnBitmap;
}

enter image description here

问题是图像在中心周围没有正确旋转。这有点偏,我似乎无法理解为什么。有什么建议吗?

0 个答案:

没有答案