作者anndy (FIFA 2006 好精彩阿)
看板C_Sharp
標題Re: [問題] 圖片做旋轉
時間Thu Mar 11 11:56:56 2010
參數說明
b :傳入欲旋轉的圖
angle :傳入旋轉角度順時鐘為正
return 輸出為旋轉過後的圖
private
Bitmap rotateImage(
Bitmap b,
float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap =
new Bitmap(b.Width*2, b.Height*2);
//make a graphics object from the empty bitmap
Graphics g =
Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((
float)b.Width, (
float)b.Height);
//rotate
g.RotateTransform(angle);
//move back
g.TranslateTransform(-(
float)b.Width, -(
float)b.Height);
//draw passed in image onto graphics object
g.DrawImage(b,
new Point(b.Width/2, b.Height/2));
return returnBitmap;
}
很久之前寫的不知道有沒有錯誤
您就參考看看囉
※ 引述《sorkayi (尋找奶昔)》之銘言:
: ※ 引述《sorkayi (尋找奶昔)》之銘言:
: : 目前在寫一個程式
: : 要做的是圖片的旋轉
: : 我想要讓圖片在原地做旋轉
: : 角度是任意給的
: : 請問板上有大大有做過類似的嗎
: : 公式或演算法都可以
: : 先謝謝了
: 自問自答一下
: 這星期學長下來幫幫
: 有給我一個提示說有一個affineTransformation的函式可以算坐標
: 請問有先進有用過嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.218.165.125
1F:推 wesley412:PUSH!! 03/11 15:31
2F:推 sorkayi:推一下 大大我有照著做了 怎麼我做出來的結果好像怪怪的 03/11 16:06
3F:→ sorkayi:有找到新方法了 用 matrix 類別去做了 03/11 16:07
※ 編輯: anndy 來自: 61.218.165.125 (03/11 20:10)