Re: [問題] 圖片做旋轉
參數說明
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
推
03/11 15:31, , 1F
03/11 15:31, 1F
推
03/11 16:06, , 2F
03/11 16:06, 2F
→
03/11 16:07, , 3F
03/11 16:07, 3F
※ 編輯: anndy 來自: 61.218.165.125 (03/11 20:10)
討論串 (同標題文章)