所以我有一个背景图片大小为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;
}
问题是图像在中心周围没有正确旋转。这有点偏,我似乎无法理解为什么。有什么建议吗?