//</snippet3> // The following code example demonstrates using a Matrix // and the GraphicsPath.Transform method to rotate a string. // This example is designed to be used with Windows Forms. // Create a form and paste the following code into it. Call the // DrawVerticalStringFromBottomUp method in the form's Paint // event-handling method, passing e as PaintEventArgs. //<snippet5> public void DrawVerticalStringFromBottomUp(PaintEventArgs e) { // Create the string to draw on the form. string text = "Can you read this?"; // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // Add the string to the path; declare the font, font style, size, and // vertical format for the string. path.AddString(text, this.Font.FontFamily, 1, 15, new PointF(0.0F, 0.0F), new StringFormat(StringFormatFlags.DirectionVertical)); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); // Set the SmoothingMode to high quality for best readability. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // Fill in the path to draw the string. e.Graphics.FillPath(Brushes.Red, path); // Dispose of the path. path.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics myGraphics = e.Graphics; Pen myPen = new Pen(Color.Black, 1.0f); GraphicsPath gp = new GraphicsPath(); Matrix RotationTransform; float centerX = this.Size.Width / 2f; float centerY = this.Size.Height / 2f; gp.AddPolygon(new PointF[] { new PointF(centerX, centerY - 5), new PointF(centerX-5, centerY + 5), new PointF(centerX+5, centerY + 5) }); RotationTransform = new Matrix(1, 0, 0, 1, 0, 0); // rotation matrix PointF RotationPoint = new PointF(centerX, centerY); // rotation point RotationTransform.RotateAt(heading, RotationPoint); gp.Transform(RotationTransform); myGraphics.FillPath(myPen.Brush, gp); myGraphics.DrawPath(myPen, gp); myPen.Dispose(); gp.Dispose(); }
/// <summary> /// Draw Function.</summary> /// <param name="g">Graphics for Drawing</param> public void Draw(Graphics g, float rollAngle, float pitchAngle) { Matrix transformMatrix = new Matrix(); transformMatrix.RotateAt(rollAngle, center); transformMatrix.Translate(0, pitchAngle * pixelPerDegree); // Previous major graduation value next to currentValue. int majorGraduationValue = ((int)(pitchAngle / 10) * 10); for (int degree = majorGraduationValue - 20; degree <= majorGraduationValue + 20; degree += 5) { if (degree == 0) continue; int width = degree % 10 == 0 ? 60 : 30; GraphicsPath skyPath = new GraphicsPath(); skyPath.AddLine(center.X - width, center.Y - degree * pixelPerDegree, center.X + width, center.Y - degree * pixelPerDegree); skyPath.Transform(transformMatrix); g.DrawPath(drawingPen, skyPath); //g.DrawString(degree.ToString(), SystemFonts.DefaultFont, Brushes.White, center.X - width - 15, center.Y - degree * 10); } }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { // Создаем траекторию GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 150, 150); path.AddRectangle(rect); // Создаем градиентную кисть PathGradientBrush pgBrush = new PathGradientBrush(path.PathPoints); // Уснинавливаем цвета кисти pgBrush.CenterColor = Color.Red; pgBrush.SurroundColors = new Color[] { Color.Blue }; // Создаем объект Matrix Matrix X = new Matrix(); // Translate X.Translate(30.0f, 10.0f, MatrixOrder.Append); // Rotate X.Rotate(10.0f, MatrixOrder.Append); // Scale X.Scale(1.2f, 1.0f, MatrixOrder.Append); // Shear X.Shear(.2f, 0.03f, MatrixOrder.Prepend); // Применяем преобразование к траектории и кисти path.Transform(X); pgBrush.Transform = X; // Выполняем визуализацию g.FillPath(pgBrush, path); } }
/// <summary> /// Изчертава елипсите. /// </summary> /// <param name="graphics"></param> public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddEllipse(Location.X + ModelSize.Width / 3, Location.Y + ModelSize.Height / 3, ModelSize.Width / 3, ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X + (ModelSize.Width * 2) / 3, Location.Y + ModelSize.Height / 2, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 2); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); /* * Създава се Pen, който изчертава контура, като използва * цвят и дебелина (определят се от конструктора) */ Pen pen = new Pen(this.BorderColor, this.BorderWidth); // Правим същото, но за запълването if (IS_FILLED) { SolidBrush brush = new SolidBrush(this.FillColor); graphics.FillPath(brush, path); } graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
public static Bitmap RotateImage(Image img, float theta) { Matrix matrix = new Matrix(); matrix.Translate(img.Width / -2, img.Height / -2, MatrixOrder.Append); matrix.RotateAt(theta, new Point(0, 0), MatrixOrder.Append); using (GraphicsPath gp = new GraphicsPath()) { gp.AddPolygon(new Point[] { new Point(0, 0), new Point(img.Width, 0), new Point(0, img.Height) }); gp.Transform(matrix); PointF[] pts = gp.PathPoints; Rectangle bbox = BoundingBox(img, matrix); Bitmap bmpDest = new Bitmap(bbox.Width, bbox.Height); using (Graphics gDest = Graphics.FromImage(bmpDest)) { Matrix mDest = new Matrix(); mDest.Translate(bmpDest.Width / 2, bmpDest.Height / 2, MatrixOrder.Append); gDest.Transform = mDest; gDest.CompositingQuality = CompositingQuality.HighQuality; gDest.InterpolationMode = InterpolationMode.HighQualityBicubic; gDest.DrawImage(img, pts); return bmpDest; } } }
public OutlinedStringSurface( String str, Font font, Brush brush, Pen outlinePen, StringFormat stringFormat) { Contract.Requires(str != null); Contract.Requires(font != null); Contract.Requires(brush != null); Contract.Requires(outlinePen != null); _brush = brush; _outlinePen = outlinePen; // グラフィックスパスの生成 _path = new GraphicsPath(); _path.AddString( str, font.FontFamily, (int)font.Style, font.Size, new Point(0, 0), stringFormat); // サイズを取得する var rect = _path.GetBounds(); Size = rect.Size.ToSize(); // 描画時にマージンがなくなるように平行移動 var matrix = new Matrix(1, 0, 0, 1, -rect.Left, -rect.Top); _path.Transform(matrix); // 描画位置を(0, 0)で記憶 matrix.Reset(); _matrix = matrix; }
public override void DrawYourSelf(Graphics graphics) { int i = 0; Point[] points = new Point[this.pointsList.Count];//(Point[])pointsList.ToArray(typeof(Point)); foreach(Point _point in this.pointsList) { points[i] = _point; i++; } GraphicsPath path = new GraphicsPath(); path.AddPolygon(points); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); if (IS_FILLED) { SolidBrush brush = new SolidBrush(this.FillColor); graphics.FillPath(brush, path); } graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
/// <summary> /// Изчертава правоъгълника. /// </summary> /// <param name="graphics"></param> public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(Location, ModelSize)); path.Transform(this.TMatrix.TransformationMatrix); /** * Създава се Pen, който изчертава контура, като използва * цвят и дебелина (определят се от конструктора) **/ Pen pen = new Pen(this.BorderColor, this.BorderWidth); /* * Създава се SolidBrush, която изпълва фигурата, като използва * цвят (определя се от конструктора) */ SolidBrush brush = new SolidBrush(this.FillColor); /* * Функция на namespace System.Drawing.Drawing2D * Изпълва контура на елипсата чрез SolidBrush */ if (IS_FILLED) { graphics.FillPath(brush, path); } /* * Функция на namespace System.Drawing.Drawing2D * Изчертава контура на елипсата чрез Pen */ graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddLine(Location.X, Location.Y + ModelSize.Height / 3, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X, Location.Y + (ModelSize.Height / 3) * 2, Location.X + ModelSize.Width, Location.Y + (ModelSize.Height * 2) / 3); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); if (IS_FILLED) { SolidBrush brush = new SolidBrush(this.FillColor); graphics.FillPath(brush, path); } graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
/// <summary> /// Функция вычисления вершин квадрата по двум смежным вершинам /// </summary> /// <param name="pt1">Первая вершина</param> /// <param name="pt2">Вторая вершина</param> /// <returns>Функция возвращает массив точек, являющихся вершинами квадрата</returns> PointF[] GetSquareVertices(PointF pt1, PointF pt2) { using (System.Drawing.Drawing2D.GraphicsPath square = new System.Drawing.Drawing2D.GraphicsPath()) { //Разность координат (с учётом знака) float deltaX = pt1.X - pt2.X, deltaY = pt1.Y - pt2.Y; //Расстояние между точками float dist = (float)Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); //Угол наклона стороны double angle; //Прямоугольник с вычисленной длиной стороны square.AddRectangle(RectangleF.FromLTRB(0, 0, dist, dist)); //Вычисление угла поворота angle = Math.Atan(deltaY / deltaX); //Посколько функция Math.Atan возвращает угол в пределах [-π/2;π/2], //то нужно пересчитать его в пределы [0;2π]. Для этого смотрим знак разности координат. //Квадранты считаются с правого нижнего против часовой стрелки. //Первый квадрант [0;π/2) получается сам собой при вычислении арктангенса if ((deltaX > 0 && deltaY <= 0) || (deltaX >= 0 && deltaY > 0)) {//Второй квадрант [π/2;π) или третий квадрант [π;3π/2) angle = Math.PI + angle; } else if (deltaX <= 0 && deltaY > 0) {//Четвёртый квадрант [3π/2;2π) angle = 2 * Math.PI + angle; } //Перевод угла из радиан в градусы angle *= 180 / Math.PI; //Перенос начала координат в первую точку и //поворот прямоугольника на вычисленный угол относительно этого нового начала координат using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, pt.X, pt.Y)) { m.RotateAt((float)angle, new PointF()); square.Transform(m); } return square.PathPoints; } }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.AddEllipse(Location.X, Location.Y, 5, 5); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
/// <summary> /// draw the line /// </summary> /// <param name="g">drawing object</param> /// <param name="translate">translation between drawn sketch and geometry object</param> public override void Draw(Graphics g, Matrix translate) { m_transform = translate; GraphicsPath path = new GraphicsPath(); path.AddLine(m_line.StartPnt, m_line.EndPnt); path.Transform(translate); g.DrawPath(m_pen, path); }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.AddBezier(pointOne, pointTwo, pointTree, pointFour); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(Location.X, Location.Y, ModelSize.Width, ModelSize.Width)); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
private void Form2_Paint(object sender, PaintEventArgs e) { //패스 그래디언트 Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) }; PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile); e.Graphics.FillRectangle(B, ClientRectangle); //패스 그래디언트 끝 //패스변형 GraphicsPath Path = new GraphicsPath(); Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat()); //확장 후 외곽선 그리기 Path.Widen(new Pen(Color.Black, 3)); e.Graphics.DrawPath(Pens.Black, Path); //확장 후 채우기 Path.Widen(new Pen(Color.Blue, 3)); e.Graphics.DrawPath(Pens.Black, Path); //곡선 펴기 Path.Flatten(new Matrix(), 12f); e.Graphics.DrawPath(Pens.Black, Path); //회전 Matrix M = new Matrix(); M.Rotate(-10); Path.Transform(M); e.Graphics.FillPath(Brushes.Blue, Path); //휘기 RectangleF R = Path.GetBounds(); PointF[] arPoint = new PointF[4]; arPoint[0] = new PointF(R.Left, R.Top + 30); arPoint[1] = new PointF(R.Right, R.Top - 10); arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10); arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30); Path.Warp(arPoint, R); e.Graphics.FillPath(Brushes.Blue, Path); //클리핑 //graphicspath path= new graphicspath(); //path.fillmode = fillmode.winding; //path.addellipse(50, 10, 100, 80); //path.addellipse(20, 45, 160, 120); //e.graphics.fillpath(brushes.white, path); //e.graphics.setclip(path); //for (int y = 0; y < bottom; y+= 20) //{ // string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다"; // e.graphics.drawstring(str, font, brushes.blue, 0, y); //} //클리핑 끝 }
public void Zoom(float oldzoom, float newzoom) { var newfact = (1 / oldzoom) * newzoom; using (var mx = new Matrix(newfact, 0f, 0f, newfact, 0f, 0f)) { _Geometry.Transform(mx); } }
protected override void UpdatePath() { InternalPath = new GraphicsPath(); InternalPath.AddPie(this.Left, this.Top, this.Width, this.Height, this.StartAngle, this.SweepAngle); Matrix mtx = new Matrix(); mtx.RotateAt(this.Rotation, InternalRotationBasePoint); InternalPath.Transform(mtx); }
public override RectangleF ReturnBounds() { Point[] points = (Point[])pointsList.ToArray(typeof(Point)); GraphicsPath path = new GraphicsPath(); path.AddCurve(points,1); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
protected override void UpdatePath() { InternalPath = new GraphicsPath(); InternalPath.AddArc(_left, _top, _width, _height, _startAngle, _sweepAngle); Matrix mtx = new Matrix(); mtx.RotateAt(this.Rotation, InternalRotationBasePoint); InternalPath.Transform(mtx); }
private static void MoveGraphicsPath(GraphicsPath gp, int x, int y) { using (Matrix matrix = new Matrix()) { gp.CloseFigure(); matrix.Translate(x, y); gp.Transform(matrix); } }
protected override void UpdatePath() { if (this.Points == null || this.Points.Length == 0) return; InternalPath = new GraphicsPath(); InternalPath.AddCurve(this.Points); Matrix mtx = new Matrix(); mtx.RotateAt(this.Rotation, InternalRotationBasePoint); InternalPath.Transform(mtx); }
public bool HitTest(Point p) { GraphicsPath gp = new GraphicsPath(); Matrix mtx = new Matrix(); Pen pen = new Pen(el.BorderColor, el.BorderWidth + 4); pen.StartCap = el.StartCap; pen.EndCap = el.EndCap; gp.AddLine(el.Point1, el.Point2); gp.Transform(mtx); //Rectangle retGp = Rectangle.Round(gp.GetBounds()); return gp.IsOutlineVisible (p, pen); }
public override bool HitTest(System.Drawing.Point p) { GraphicsPath gp = new GraphicsPath(); Matrix mtx = new Matrix(); gp.AddEllipse(new Rectangle(el.Location.X, el.Location.Y, el.Size.Width, el.Size.Height)); gp.Transform(mtx); return gp.IsVisible(p); }
public bool HitTest(Rectangle r) { GraphicsPath gp = new GraphicsPath(); Matrix mtx = new Matrix(); gp.AddRectangle(new Rectangle(el.Location.X, el.Location.Y, el.Size.Width, el.Size.Height)); gp.Transform(mtx); Rectangle retGp = Rectangle.Round(gp.GetBounds()); return r.Contains (retGp); }
public void Draw(KalikoImage image) { var graphics = image.Graphics; var graphicsPath = new GraphicsPath(); var stringFormat = new StringFormat { Alignment = Alignment, LineAlignment = VerticalAlignment }; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; if (Font == null) { Font = image.Font ?? new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel); } if (TargetArea == Rectangle.Empty) { TargetArea = new Rectangle(0, 0, image.Width, image.Height); } if (Point == Point.Empty) { graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, TargetArea, stringFormat); } else { graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Point, stringFormat); } if (Rotation != 0) { var rotationTransform = new Matrix(1, 0, 0, 1, 0, 0); var bounds = graphicsPath.GetBounds(); rotationTransform.RotateAt(Rotation, new PointF(bounds.X + (bounds.Width / 2f), bounds.Y + (bounds.Height / 2f))); graphicsPath.Transform(rotationTransform); } if (TextShadow != null) { DrawShadow(graphics, graphicsPath); } if (Outline > 0) { var pen = new Pen(OutlineColor, Outline) { LineJoin = LineJoin.Round }; graphics.DrawPath(pen, graphicsPath); } if (TextBrush == null) { TextBrush = new SolidBrush(TextColor); } graphics.FillPath(TextBrush, graphicsPath); }
/// <summary> /// This routine draws the animated bomb /// using two toggling graphics paths /// giving the effect of a spinning bomb /// </summary> /// <param name="g"></param> public override void Draw(Graphics g) { UpdateBounds(); Matrix m = new Matrix(); m.Translate(MovingBounds.Left, MovingBounds.Top); // g.FillRectangle(Brushes.White , MovingBounds); if (_invert) { bombInTransformed = (GraphicsPath)bombIn.Clone(); bombInTransformed.Transform(m); g.DrawPath(BombPen, bombInTransformed); bombInTransformed.Dispose(); } else { bombOutTransformed = (GraphicsPath)bombOut.Clone(); bombOutTransformed.Transform(m); g.DrawPath(BombPen, bombOutTransformed); bombOutTransformed.Dispose(); } /* Matrix flipMatrix = new Matrix(); flipMatrix.Scale(-1.0f, 1.0f); m.Translate(MovingBounds.Left, MovingBounds.Top); if (_invert) { m.Scale(-1, 1); // flip around the y axis } // g.FillRectangle(Brushes.White , MovingBounds); bombInTransformed = (GraphicsPath)bombIn.Clone(); bombInTransformed.Transform(m); g.DrawPath(BombPen, bombInTransformed); bombInTransformed.Dispose(); */ _invert = !_invert; // g.DrawPolygon(Pens.White, new PointF[]{new PointF(Position.X, Position.Y), // new PointF(Position.X + width, Position.Y + seg), // new PointF(Position.X, Position.Y + seg*2), // new PointF(Position.X + 3, Position.Y + seg*3)}); Position.Y += TheBombInterval; }
public virtual bool HitTest(Point p) { GraphicsPath gp = new GraphicsPath(); Matrix mtx = new Matrix(); Point elLocation = el.Location; Size elSize = el.Size; gp.AddRectangle(new Rectangle(elLocation.X, elLocation.Y, elSize.Width, elSize.Height)); gp.Transform(mtx); return gp.IsVisible(p); }
public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.AddBezier(pointOne, pointTwo, pointTree, pointFour); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddLine(Location.X, Location.Y + ModelSize.Height / 3, Location.X + ModelSize.Width, Location.Y + ModelSize.Height / 3); path.CloseFigure(); path.StartFigure(); path.AddLine(Location.X, Location.Y + (ModelSize.Height / 3) * 2, Location.X + ModelSize.Width, Location.Y + (ModelSize.Height * 2) / 3); path.CloseFigure(); path.AddEllipse(new RectangleF(Location, ModelSize)); path.CloseFigure(); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.AddEllipse(Location.X, Location.Y, 5, 5); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
bool Dalssoft.DiagramNet.IController.HitTest(Rectangle r) { GraphicsPath gp = new GraphicsPath(); Matrix mtx = new Matrix(); Point elLocation = el.Location; Size elSize = el.Size; gp.AddRectangle(new Rectangle(elLocation.X, elLocation.Y, elSize.Width, elSize.Height)); gp.Transform(mtx); Rectangle retGp = Rectangle.Round(gp.GetBounds()); return r.Contains (retGp); }
public static Bitmap CreateFillPolygon(Device d, GraphicsPath path, Brush brush) { RectangleF rectF = path.GetBounds(); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.Translate(-rectF.X, -rectF.Y); path.Transform(m); AGT_TextureResource gdi = new AGT_TextureResource(rectF.Width, rectF.Height); if (gdi != null) { Graphics g = gdi.GetGraphics(); if (g != null) { g.FillPath(brush, path); return gdi.ToBitmap(); } } return null; }
internal void Transform(Matrix matrix) { if (matrix.IsIdentity) { return; // bail out } byte[] oldData = (byte[])this.data.Clone(); // this.Clone().Data ; int oldSize = 8 + GetInt32(oldData, 0); int nrOps2 = GetInt32(oldData, 12); int readPointer = StartRegionData(); int writePointer = readPointer; float m11 = matrix.Elements[0]; float m12 = matrix.Elements[1]; float m21 = matrix.Elements[2]; float m22 = matrix.Elements[3]; float dX = matrix.Elements[4]; float dY = matrix.Elements[5]; while (readPointer < oldSize) { Token T = NextToken(oldData, ref readPointer, false); Int32 tokenType = GetInt32(T.rawData, 0); switch (tokenType) { case REG_RECT: { RectangleF rect = GetRectangle(T.rawData); if ((m12 == 0.0f) && (m21 == 0.0f)) { // in this case, rect transforms to another rectangle rect.X = (m11 < 0) ? m11 * (rect.X + rect.Width) : m11 * rect.X; rect.X += dX; /* there is actually a BUG in Microsoft's .NET * 1.1 implementation: * for (m22<0) they evaluate rect.Y to be * m22*(rect.Y+rect.Height), which cannot be possible * by simple geometric reasoning... */ rect.Y = (m22 < 0) ? m22 * (rect.Y - rect.Height) : m22 * rect.Y; rect.Y += dY; rect.Width = (m11 < 0) ? -m11 * rect.Width : m11 * rect.Width; rect.Height = (m22 < 0) ? -m22 * rect.Height : m22 * rect.Height; writePointer = AddRegionRectangle(rect, writePointer); } else { // rectangular shape is not preserved -> use a graphics path GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); path.Transform(matrix); writePointer = AddRegionPath(path, writePointer); } } break; case REG_PATH: { GraphicsPath path = GetPath(T.rawData); path.Transform(matrix); writePointer = AddRegionPath(path, writePointer); } break; default: { // other tokens are not concerned writePointer = AddRawData(T.rawData, writePointer); } break; } } WriteHeader(writePointer - 8, nrOps2); Resize(writePointer); }
public void Form1_Paint(object sender, PaintEventArgs e) { ////// // Create a graphics path and add an ellipse. ////// GraphicsPath myPath = new GraphicsPath(); ////// Rectangle rect = new Rectangle(100, 20, 100, 50); ////// myPath.AddRectangle(rect); ////// // Get the path's array of points. ////// PointF[] myPathPointArray = myPath.PathPoints; ////// // Create a path gradient brush. ////// PathGradientBrush myPGBrush = new ////// PathGradientBrush(myPathPointArray); ////// // Set the color span. ////// myPGBrush.CenterColor = Color.Green; ////// Color[] mySurroundColor = { Color.Blue }; ////// myPGBrush.SurroundColors = mySurroundColor; ////// // Draw the brush to the screen prior to transformation. ////// e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200); ////// // Apply the rotate transform to the brush. ////// myPGBrush.RotateTransform(a, MatrixOrder.Append); ////// // Draw the brush to the screen again after applying the ////// // transform. ////// e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300); GraphicsPath path = new GraphicsPath(); int Wi = 0; int Hi = 0; path.AddEllipse(160, 70, 150, 70); // Use the path to construct a brush. PathGradientBrush pthGrBrush = new PathGradientBrush(path); // Set the color at the center of the path to blue. pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255); //pthGrBrush.FocusScales = new PointF(40, 40); // Set the color along the entire boundary // of the path to aqua. Color[] colors = { Color.FromArgb(255, 0, 255, 255) }; pthGrBrush.SurroundColors = colors; pthGrBrush.RotateTransform(a); for (int t = 0; t < 100; t++) { PointF wq = new PointF(); wq.X = 40; wq.Y = 40; pthGrBrush.TranslateTransform(1, 1); e.Graphics.FillRectangle(pthGrBrush, 0, 0, 700, 700); Invalidate(); } Bitmap bm = new Bitmap(img.Width, img.Height); if (a <= 90) { Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360)); Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360)); } else if (a > 90 && a <= 180) { Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360)); Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360)); } else if (a > 180 && a <= 270) { Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360)); Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360)); } else if (a > 270 && a <= 360) { Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360)); Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360)); } Bitmap b = new Bitmap(Wi, Hi); g.TranslateTransform(Wi / 2, Hi / 2); g.RotateTransform(a); g.TranslateTransform(-img.Width / 2, -img.Height / 2); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(img, 0, 0); e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2); e.Graphics.DrawImage(b, -b.Width / 2, -b.Height / 2); Create the string to draw on the form. string text = "Roma prodakshen"; // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // Add the string to the path; declare the font, font style, size, and // vertical format for the string. path.AddString(text, this.Font.FontFamily, 1, 15, new PointF(100.0F, 50.0F), new StringFormat(StringFormatFlags.DirectionVertical)); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(a, new PointF(200.0F, 50.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); // Set the SmoothingMode to high quality for best readability. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // Fill in the path to draw the string. e.Graphics.FillPath(Brushes.GreenYellow, path); // Dispose of the path. path.Dispose(); }
public void Transform(IMatrix matrix) { Control.Transform(matrix.ToSD()); }