我需要通過旋轉圖像解決的一個問題,但我有這樣的代碼將圖像旋轉不旋轉完全如何旋轉圖片框
public static Image RotateImage(Image img, float rotationAngle)
{
//create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);
//turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);
//now we set the rotation point to the center of our image
gfx.TranslateTransform((float)bmp.Width/2, (float)bmp.Height/2);
//now rotate the image
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(-(float)bmp.Width/2, -(float)bmp.Height/2);
//set the InterpolationMode to HighQualityBicubic so to ensure a high
//quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//now draw our new image onto the graphics object
gfx.DrawImage(img, new System.Drawing.Point(0, 0));
//dispose of our Graphics object
gfx.Dispose();
//return the image
return bmp;
}
並使用它來調用方法。右邊是旋轉包含圖像的矩形,並避免切割圖像
Bitmap bitmap = (Bitmap)Pix.Image;
Pix.Image = (Bitmap)(RotateImage(bitmap, 20.0f));
可能重複[LockBits圖像旋轉方法不工作?](http://stackoverflow.com/questions/3860030/lockbits-image-rotation-method-not-working) – 2012-04-22 17:42:47