以下是一個旋轉圖片的範例,但是根據我的測試,轉的結果不甚理想。雖然選轉中心點已經設為中間了,但是常常會偏移。
public static Image RotateImage(
Image img,
float rotationAngle)
{
Bitmap bmp =
new Bitmap(img.Width, img.Height);
//建立同大小圖片 Graphics gfx =
Graphics.FromImage(bmp);
gfx.RotateTransform(rotationAngle);
//依照傳入角度旋轉圖片 gfx.TranslateTransform((
float)bmp.Width / 2, (
float)bmp.Height / 2);
//建立旋轉點,這一行是取圖片中心點 gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//設定InterpolationMode為HighQualityBicubic,確保旋轉後不會變形 gfx.DrawImage(img,
new Point(0, 0));
//重新畫上圖片 gfx.Dispose();
return bmp;
}