創作內容

1 GP

C#旋轉圖片

作者:怪鳥│2011-02-01 13:57:09│巴幣:2│人氣:2271
以下是一個旋轉圖片的範例,但是根據我的測試,轉的結果不甚理想。雖然選轉中心點已經設為中間了,但是常常會偏移。
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;
}
引用網址:https://home.gamer.com.tw/TrackBack.php?sn=1222347
All rights reserved. 版權所有,保留一切權利

相關創作

同標籤作品搜尋:C#|VB.Net|ASP.Net

留言共 1 篇留言

semmyenator
public static Image RotateImage(Image img, float rotationAngle)
{
Bitmap bmp = new Bitmap(img.Width, img.Height);
//Create same-size images.

Graphics gfx = Graphics.FromImage(bmp);

gfx.RotateTransform(rotationAngle);
//Rotate the image according to the incoming angle.

gfx.TranslateTransform((float)bmp.Width / 2 - img.Width / 2, (float)bmp.Height / 2 - img.Height / 2);
//Create a rotation point, this line is the center point of the image.

gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//Set InterpolationMode to HighQualityBicubic to ensure that it does not deform after rotation.

gfx.DrawImage(img, new Point(0, 0));
//Redraw the picture.

gfx.Dispose();
return bmp;
}

10-06 21:41

我要留言提醒:您尚未登入,請先登入再留言

1喜歡★stbird 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:Flex下的margin... 後一篇:objective c的...

追蹤私訊切換新版閱覽

作品資料夾

yvonne40528歡迎來讀新詩ゝω・
是哪一盞清脆光點/指引我穿越一叢叢幽暗怒火/腳步並非已無朦朧/深淵的勸誘依舊格外香甜魅惑看更多我要大聲說39分前


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】