图像旋转
一個(gè)坐標(biāo)點(diǎn)圍繞任意中心點(diǎn)旋轉(zhuǎn)--C#實(shí)現(xiàn)
分類: C#/ASP.net 重用代碼之C# 2011-07-19 20:23 1668人閱讀 評(píng)論(0) 收藏 舉報(bào)假設(shè)對(duì)圖片上任意點(diǎn)(x,y),繞一個(gè)坐標(biāo)點(diǎn)(rx0,ry0)逆時(shí)針旋轉(zhuǎn)RotaryAngle角度后的新的坐標(biāo)設(shè)為(x', y'),有公式:x'= (x - rx0)*cos(RotaryAngle) + (y - ry0)*sin(RotaryAngle) + rx0 ;y'=-(x - rx0)*sin(RotaryAngle) + (y - ry0)*cos(RotaryAngle) + ry0 ;
[csharp] view plaincopy
/// <summary> /// 對(duì)一個(gè)坐標(biāo)點(diǎn)按照一個(gè)中心進(jìn)行旋轉(zhuǎn) /// </summary> /// <param name="center">中心點(diǎn)</param> /// <param name="p1">要旋轉(zhuǎn)的點(diǎn)</param> /// <param name="angle">旋轉(zhuǎn)角度,笛卡爾直角坐標(biāo)</param> /// <returns></returns> private Point PointRotate(Point center, Point p1, double angle) { Point tmp = new Point(); double angleHude = angle * Math.PI / 180;/*角度變成弧度*/ double x1 = (p1.X - center.X) * Math.Cos(angleHude) + (p1.Y - center.Y ) * Math.Sin(angleHude) + center .X; double y1 = -(p1.X - center.X) * Math.Sin(angleHude) + (p1.Y - center.Y) * Math.Cos(angleHude) + center.Y; tmp.X = (int)x1; tmp.Y = (int)y1; return tmp; }
?
?
?
1 、旋轉(zhuǎn)e.Graphics.RotateTransform(30.0F, MatrixOrder.Prepend);2、平移e.Graphics.TranslateTransform(100.0F, 0.0F);3、縮放e.Graphics.ScaleTransform(3.0F, 1.0F, MatrixOrder.Append); 4、點(diǎn)坐標(biāo)變換e.Graphics.TranslateTransform(40, 30);e.Graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, points);e.Graphics.ResetTransform();// Create array of two points.Point[] points = { new Point(0, 0), new Point(100, 50) };// Draw line connecting two untransformed points.e.Graphics.DrawLine(new Pen(Color.Blue, 3), points[0], points[1]);// Set world transformation of Graphics object to translate.e.Graphics.TranslateTransform(40, 30);// Transform points in array from world to page coordinates. e.Graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, points);// Reset world transformation. e.Graphics.ResetTransform();// Draw line that connects transformed points.e.Graphics.DrawLine(new Pen(Color.Red, 3), points[0], points[1]);5、選擇參數(shù):將此變換參數(shù)放在已有的變換矩陣之后還是之前。MatrixOrder.Append//MatrixOrder.Prepend //----------------旋轉(zhuǎn)和平移的順序不一樣,得到的結(jié)果頁(yè)不一樣。6、輔助功能GraphicsState transState = e.Graphics.Save();//保存當(dāng)前繪圖板狀態(tài) e.Graphics.ResetTransform();//重置 e.Graphics.Restore(transState);//置為此狀態(tài)?
轉(zhuǎn)載于:https://www.cnblogs.com/anbylau2130/p/3167612.html
總結(jié)
- 上一篇: 什么是实物交割
- 下一篇: [原]逆向iOS SDK -- +[UI