protected override void OnPaint(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.CompositingMode = CompositingMode.SourceOver; GraphicsPath stroke = new GraphicsPath(); stroke.AddString(this.Text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); string tmp = this.Text; while (stroke.GetBounds().Width > this.Width - 8) { tmp = tmp.Substring(0, tmp.Length - 1); stroke = new GraphicsPath(); stroke.AddString(tmp + "...", this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); } RectangleF bounds = stroke.GetBounds(); Matrix translationMatrix = new Matrix(); if (this.TextAlign == ContentAlignment.TopRight || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.BottomRight) { translationMatrix.Translate(this.Width - bounds.Width - 8, 0); } else if (this.TextAlign == ContentAlignment.TopCenter || this.TextAlign == ContentAlignment.MiddleCenter || this.TextAlign == ContentAlignment.BottomCenter) { translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, 0); } if (this.TextAlign == ContentAlignment.MiddleLeft || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.MiddleCenter) { translationMatrix.Translate(0, (this.Height - bounds.Height - 5) / 2); } else if (this.TextAlign == ContentAlignment.BottomLeft || this.TextAlign == ContentAlignment.BottomCenter || this.TextAlign == ContentAlignment.BottomRight) { translationMatrix.Translate(0, (this.Height - bounds.Height - 5)); } stroke.Transform(translationMatrix); e.Graphics.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */ e.Graphics.FillPath(Brushes.White, stroke); /* Text */ }
public override void DrawFigure(Graphics g) { using (GraphicsPath gp = new GraphicsPath()) { AddRectanglePath(gp); RectangleF bounds = gp.GetBounds(); g.FillPath(this.Fill.Brush(bounds), gp); // Заливка фона g.DrawPath(this.Stroke.Pen(), gp); // Рисование контура using (Font font = this.Text.Font()) { StringFormatFlags options = this.Text.Vertical ? StringFormatFlags.DirectionVertical : (StringFormatFlags)0; using (StringFormat format = new StringFormat(options)) { format.LineAlignment = this.Text.LineAlignment; format.Alignment = this.Text.Alignment; using (Brush brush = this.Text.FontBrush()) g.DrawString(this.Text.Caption, font, brush, bounds, format); } } } }
/// <summary> /// Handles the drawing code for linear gradient paths. /// </summary> /// <param name="g">Graphics object used for drawing.</param> /// <param name="gp">Path that gets drawn.</param> public override void FillPath(Graphics g, GraphicsPath gp) { RectangleF bounds = Bounds; if (bounds.IsEmpty) { bounds = gp.GetBounds(); } if (bounds.Width == 0 || bounds.Height == 0) { return; } // also don't draw gradient for very small polygons if (bounds.Width < 0.01 || bounds.Height < 0.01) { return; } if (GradientType == GradientType.Linear) { using LinearGradientBrush b = new(bounds, Colors[0], Colors[Colors.Length - 1], (float) - Angle);
private void DrawRotatedText(Graphics gr, string text, float angle, PointF pointCenter) { angle -= _rotateDegree; gr.SmoothingMode = SmoothingMode.HighQuality; gr.CompositingQuality = CompositingQuality.HighQuality; gr.TextRenderingHint = TextRenderingHint.AntiAlias; GraphicsPath graphicsPath = new GraphicsPath(FillMode.Winding); int x = (int)pointCenter.X; int y = (int)pointCenter.Y; switch (TextPathPathPosition) { case TextPathPosition.OverPath: graphicsPath.AddString(text, _font.FontFamily, (int)_font.Style, _font.Size, new Point(x, (int)(y - _font.Size)), _stringFormat); break; case TextPathPosition.CenterPath: graphicsPath.AddString(text, _font.FontFamily, (int)_font.Style, _font.Size, new Point(x, (int)(y - _font.Size / 2)), _stringFormat); break; case TextPathPosition.UnderPath: graphicsPath.AddString(text, _font.FontFamily, (int)_font.Style, _font.Size, new Point(x, y), _stringFormat); break; } Matrix rotationMatrix = new Matrix(); rotationMatrix.RotateAt(angle, new PointF(x, y)); graphicsPath.Transform(rotationMatrix); if (!_measureString) { gr.DrawPath(new Pen(_color), graphicsPath); gr.FillPath(_fillBrush, graphicsPath); } else { _regionList.Add(graphicsPath.GetBounds()); } graphicsPath.Dispose(); }
///////////////////////////////////////////////////////////////////// // Class initialization ///////////////////////////////////////////////////////////////////// private void OnLoad ( object sender, EventArgs e ) { FillColorButton.BackColor = Color.Blue; OutlineColorButton.BackColor = Color.Red; FormatComboBox.SelectedIndex = 0; // convert character to graphics path GP = new GraphicsPath(); GP.AddString(((Char)CharCode).ToString(), FontFamily, (Int32)Style, 1000, Point.Empty, StringFormat.GenericDefault); Box = GP.GetBounds(); // force resize to calculate scale and origin OnResize(null, null); // force OnPaint Invalidate(); return; }
/// <summary> /// Render this object to the specified <see cref="Graphics"/> device. /// </summary> /// <remarks> /// This method is normally only called by the Draw method /// of the parent <see cref="GraphItemList"/> collection object. /// </remarks> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="PaneBase"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> override public void Draw(Graphics g, PaneBase pane, float scaleFactor) { if (this.points != null && this.points.Length > 1) { GraphicsPath path = MakePath(pane); // Fill or draw the symbol as required if (this.fill.IsVisible) { Brush brush = this.Fill.MakeBrush(path.GetBounds()); g.FillPath(brush, path); } if (this.border.IsVisible) { Pen pen = border.MakePen(pane.IsPenWidthScaled, scaleFactor); g.DrawPath(pen, path); } path.Dispose(); } }
/// <summary> /// 任意角度旋转 /// </summary> /// <param name="bmp">原始图Bitmap</param> /// <param name="angle">旋转角度</param> /// <param name="bkColor">背景色</param> /// <returns>输出Bitmap</returns> public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor) { int w = bmp.Width + 2; int h = bmp.Height + 2; PixelFormat pf; if (bkColor == Color.Transparent) { pf = PixelFormat.Format32bppArgb; } else { pf = bmp.PixelFormat; } Bitmap tmp = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tmp); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); Matrix mtrx = new Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf); g = Graphics.FromImage(dst); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tmp, 0, 0); g.Dispose(); tmp.Dispose(); return(dst); }
public static Size GetRotatedSize(Size oldSize, float theta) { int halfWidth = oldSize.Width / 2; int halfHeight = oldSize.Height / 2; Matrix mRotate = new Matrix(); mRotate.Translate(-halfWidth, -halfHeight, MatrixOrder.Append); mRotate.RotateAt(theta, new Point(0, 0), MatrixOrder.Append); Point topLeft = new Point(-halfWidth, -halfHeight); Point topRight = new Point(halfWidth, -halfHeight); Point bottomRight = new Point(halfWidth, halfHeight); Point bottomLeft = new Point(-halfWidth, halfHeight); Point[] points = new Point[] { topLeft, topRight, bottomRight, bottomLeft }; GraphicsPath gp = new GraphicsPath(points, new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line }); gp.Transform(mRotate); return(Size.Round(gp.GetBounds().Size)); }
public void Draw(Graphics g) { if (!this.Active) { return; } var fishColor = this.FillColor; if (this.Selected) { fishColor = Color.FromArgb((int)Math.Abs(Math.Sin(this.Ticks) * 255), fishColor.R, fishColor.G, fishColor.B); } var movedFish = new UIFishData(); movedFish.Body = new List <PointF>(this.GetFishBody(this.data.Body.ToArray(), this.Position, this.FacingDirection)); movedFish.Tail = new List <PointF>(this.GetFishTail(this.data.Tail.ToArray(), movedFish.Body.Last(), this.FacingDirection)); movedFish.Eye = this.GetFishEye(this.data.Eye, this.Position, this.FacingDirection); var path = new GraphicsPath(); var body = movedFish.Body.ToArray(); path.AddLines(body); g.FillPath(new SolidBrush(fishColor), path); path.AddLines(movedFish.Tail.ToArray()); g.FillPath(new SolidBrush(fishColor), path); g.FillEllipse(this.Predator ? Brushes.Red : Brushes.White, new RectangleF(movedFish.Eye.X - (this.BodySize), movedFish.Eye.Y - (this.BodySize), this.BodySize * 2, this.BodySize * 2)); g.FillEllipse(Brushes.Black, new RectangleF(movedFish.Eye.X - 1.0f, movedFish.Eye.Y - 1.0f, 3.5f, 3.5f)); g.DrawString( Fish.Name, new Font("Segoe UI Light", 10, FontStyle.Regular), new SolidBrush(Color.White), Position.Offset(10.0f)); this.Bounds = path.GetBounds(); }
private void confirm(GraphicsPath path) { RectangleF rect = path.GetBounds(); int left = (int)rect.Left; int top = (int)rect.Top; int width = (int)rect.Width; int height = (int)rect.Height; Graphics gra = pbImg.CreateGraphics(); gra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Brush bush = new SolidBrush(Color.Green);//填充的颜色 Pen pen = new Pen(Color.Green, 2); Rectangle r = new Rectangle(left, top, width, height); pen.DashStyle = DashStyle.Dot; gra.DrawRectangle(pen, r); gra.FillEllipse(bush, left - 5, top - 5, 10, 10); //画填充椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50 gra.FillEllipse(bush, left + width - 5, top - 5, 10, 10); //画填充椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50 gra.FillEllipse(bush, left - 5, top + height - 5, 10, 10); //画填充椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50 gra.FillEllipse(bush, left + width - 5, top + height - 5, 10, 10); //画填充椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50 }
public static void smethod_3(Bounds3D bounds, GraphicsPath path, Matrix4D transform) { if (path.PointCount == 0) { return; } RectangleF bounds1 = path.GetBounds(); PointF[] pointFArray = new PointF[4] { bounds1.Location, new PointF(bounds1.Right, bounds1.Top), new PointF(bounds1.Left, bounds1.Bottom), new PointF(bounds1.Right, bounds1.Bottom) }; Point3D point3D = new Point3D(); for (int index = 3; index >= 0; --index) { point3D.X = (double)pointFArray[index].X; point3D.Y = (double)pointFArray[index].Y; point3D.Z = 0.0; point3D = transform.Transform(point3D); bounds.Update(point3D); } }
internal void AddHotRegion(ChartGraphics graph, GraphicsPath path, bool relativePath, float[] coord, DataPoint point, string seriesName, int pointIndex) { if ((ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && common.ChartPicture.MapEnabled && (point.ToolTip.Length > 0 || point.Href.Length > 0 || point.MapAreaAttributes.Length > 0)) { common.ChartPicture.MapAreas.Insert(0, MapAreaShape.Polygon, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Href), point.ReplaceKeywords(point.MapAreaAttributes), coord, ((IMapAreaAttributes)point).Tag); } if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.SeriesName = seriesName; hotRegion.PointIndex = pointIndex; hotRegion.Type = ChartElementType.DataPoint; hotRegion.Path = path; hotRegion.BoundingRectangle = path.GetBounds(); hotRegion.RelativeCoordinates = relativePath; if (point != null && point.IsAttributeSet("OriginalPointIndex")) { hotRegion.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture); } regionList.Add(hotRegion); } }
protected override void DoPage(Graphics grfx, Color clr, int cx, int cy) { GraphicsPath path = new GraphicsPath(); // Add text to the path. path.AddString(strText, font.FontFamily, (int)font.Style, 100, new Point(0, 0), new StringFormat()); // Set the world transform. RectangleF rectfBounds = path.GetBounds(); PointF[] aptfDest = { new PointF(0, 0), new PointF(cx, 0), new PointF(0, cy) }; grfx.Transform = new Matrix(rectfBounds, aptfDest); // Fill the path. grfx.FillPath(new SolidBrush(clr), path); }
/** * <summary>Expands the size of this quad stretching around its center.</summary> * <param name="valueX">Expansion's horizontal extent.</param> * <param name="valueY">Expansion's vertical extent.</param> * <returns>This quad.</returns> */ public Quad Inflate( float valueX, float valueY ) { Matrix matrix = new Matrix(); RectangleF oldBounds = Path.GetBounds(); matrix.Translate(-oldBounds.X, -oldBounds.Y); path.Transform(matrix); matrix = new Matrix(); matrix.Scale(1 + valueX * 2 / oldBounds.Width, 1 + valueY * 2 / oldBounds.Height); path.Transform(matrix); RectangleF newBounds = path.GetBounds(); matrix = new Matrix(); matrix.Translate(oldBounds.X - (newBounds.Width - oldBounds.Width) / 2, oldBounds.Y - (newBounds.Height - oldBounds.Height) / 2); path.Transform(matrix); points = path.PathPoints; return(this); }
private Rectangle BoundingBox(Image img, Matrix matrix) { GraphicsUnit gu = new GraphicsUnit(); Rectangle rImg = Rectangle.Round(img.GetBounds(ref gu)); // Transform the four points of the image, to get the resized bounding box. Point topLeft = new Point(rImg.Left, rImg.Top); Point topRight = new Point(rImg.Right, rImg.Top); Point bottomRight = new Point(rImg.Right, rImg.Bottom); Point bottomLeft = new Point(rImg.Left, rImg.Bottom); Point[] points = { topLeft, topRight, bottomRight, bottomLeft }; GraphicsPath gp = new GraphicsPath(points, new[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line }); gp.Transform(matrix); return(Rectangle.Round(gp.GetBounds())); }
private void EndView() { Debug.WriteLine("EndView"); if (ShowPath) { var g = _canvasBuf.BeginDraw(); _gPath.Widen(_dirtyMarkerPen); g.SetClip(_gPath); g.Clear(Color.Transparent); _canvasBuf.EndDraw(); var pathDirty = Rectangle.Ceiling(_gPath.GetBounds()); pathDirty.Offset(_screenBounds.X, _screenBounds.Y); pathDirty.Intersect(_screenBounds); pathDirty.Offset(-_screenBounds.X, -_screenBounds.Y); //挪回来变为基于窗口的坐标 _canvasWindow.SetDiBitmap(_canvasBuf, pathDirty); _gPath.Reset(); _gPathDirty.Reset(); } if (_labelVisible) { var g = _canvasBuf.BeginDraw(); g.SetClip(_labelRect); g.Clear(Color.Transparent); _canvasBuf.EndDraw(); _canvasWindow.SetDiBitmap(_canvasBuf, Rectangle.Ceiling(_labelRect)); _labelPath.Reset(); HideLabel(); _labelChanged = false; } _canvasWindow.Visible = false; _labelRect = default(Rectangle);//todo: dirtyRect也是多余 }
public static Bitmap CreatePolygon(Device d, GraphicsPath path, Pen pen) { 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(); g.SmoothingMode = SmoothingMode.AntiAlias; if (g != null) { g.DrawPath(pen, path); return(gdi.ToBitmap()); } } return(null); }
public void transferpts()//将模板图中的关键点坐标转移对应到被改的图上的坐标从而进行TPS { mode2or = new double[68, 2]; RectangleF orrec = orpath.GetBounds(); RectangleF moderec = modepath.GetBounds(); float cenx1 = orrec.X + orrec.Width / 2; //原矩形和模板矩形的中心坐标 float ceny1 = orrec.Y + orrec.Height / 2; float cenx2 = moderec.X + moderec.Width / 2; float ceny2 = moderec.Y + moderec.Height / 2; float dx = cenx2 - cenx1; //偏移 float dy = ceny2 - ceny1; //先尝试按长宽缩放 float k1 = orrec.Width / moderec.Width; float k2 = orrec.Height / moderec.Width; //float k = orrec.Width * orrec.Height / (moderec.Width*moderec.Height); for (int i = 0; i < 68; i++) { mode2or[i, 0] = k1 * (mode[i, 0] - cenx2) + cenx2 - dx; mode2or[i, 1] = k2 * (mode[i, 1] - ceny2) + ceny2 - dy; } }
protected override void GeneratePath() { _Path = new GraphicsPath(); if (points[0].X == int.MaxValue) { _Path.AddLine(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue); invalidationArea = new Rectangle(0, 0, 0, 0); } else if (points[3].X == int.MaxValue) { _Path.AddLine(points[0].X, points[0].Y, points[0].X + 1, points[0].Y); InvalidationArea = new Rectangle(Point.Ceiling(points[0]), new Size(2, 2)); } else { _Path.AddCurve(points); if (!blnRefreshInvalidate) { InvalidationArea = Rectangle.Round(_Path.GetBounds()); } } }
public static Bitmap ResizeAndRotateCenter(Bitmap bmpSrc, int newWidth, int newHeight, float theta) { if (theta == 0 && bmpSrc.Width == newWidth && bmpSrc.Height == newHeight) { return(bmpSrc); } Matrix mRotate = new Matrix(); if (bmpSrc.Width != newWidth || bmpSrc.Height != newHeight) { mRotate.Scale((float)newWidth / bmpSrc.Width, (float)newHeight / bmpSrc.Height, MatrixOrder.Append); } mRotate.Translate((float)(newWidth / -2.0), (float)(newHeight / -2.0), MatrixOrder.Append); if (theta % 360 != 0 && theta % -360 != 0) { mRotate.RotateAt(-theta, new Point(0, 0), MatrixOrder.Append); } using (GraphicsPath gp = new GraphicsPath()) { // transform image points by rotation matrix gp.AddPolygon(new Point[] { new Point(0, 0), new Point(bmpSrc.Width, 0), new Point(0, bmpSrc.Height), new Point(bmpSrc.Width, bmpSrc.Height) }); gp.Transform(mRotate); PointF[] pts = gp.PathPoints; Rectangle rec = Rectangle.Round(gp.GetBounds()); // create destination bitmap sized to contain rotated source image Bitmap bmpDest = new Bitmap(rec.Width, rec.Height, bmpSrc.PixelFormat); using (Graphics gDest = Graphics.FromImage(bmpDest)) { // draw source into dest Matrix mDest = new Matrix(); mDest.Translate(bmpDest.Width / 2, bmpDest.Height / 2, MatrixOrder.Append); gDest.Transform = mDest; gDest.DrawImage(bmpSrc, new PointF[] { pts[0], pts[1], pts[2] }); return(bmpDest); } } }
//Create a list of handles protected internal override void CreateHandles() { if (Model == null) { return; } if (Points == null) { return; } SetHandles(new Handles()); //Get the default graphics path and scale it //Render render = RenderFromContainer(); GraphicsPath defaultPath = (GraphicsPath)Singleton.Instance.DefaultHandlePath.Clone(); Matrix matrix = new Matrix(); //matrix.Scale(render.ZoomFactor,render.ZoomFactor); //defaultPath.Transform(matrix); RectangleF pathRectangle = defaultPath.GetBounds(); RectangleF halfRectangle = new RectangleF(0, 0, pathRectangle.Width / 2, pathRectangle.Height / 2); //Loop through each point and add an offset handle GraphicsPath path; PointF point = (PointF)Points[0]; path = (GraphicsPath)defaultPath.Clone(); matrix.Reset(); matrix.Translate(point.X - Bounds.X - halfRectangle.Width, point.Y - Bounds.Y - halfRectangle.Height); path.Transform(matrix); Handles.Add(new Handle(path, HandleType.Origin, true)); point = (PointF)Points[Points.Count - 1]; path = (GraphicsPath)defaultPath.Clone(); matrix.Reset(); matrix.Translate(point.X - Bounds.X - halfRectangle.Width, point.Y - Bounds.Y - halfRectangle.Height); path.Transform(matrix); Handles.Add(new Handle(path, HandleType.Origin, true)); }
private void DrawTabFocusIndicator(GraphicsPath tabpath, int index, System.Drawing.Graphics graphics) { if (this._FocusTrack && this._TabControl.Focused && index == this._TabControl.SelectedIndex) { Brush focusBrush = null; RectangleF pathRect = tabpath.GetBounds(); Rectangle focusRect = Rectangle.Empty; switch (this._TabControl.Alignment) { case TabAlignment.Top: focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, 4); focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.Window, LinearGradientMode.Vertical); break; case TabAlignment.Bottom: focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Bottom - 4, (int)pathRect.Width, 4); focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Vertical); break; case TabAlignment.Left: focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, 4, (int)pathRect.Height); focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.ControlLight, LinearGradientMode.Horizontal); break; case TabAlignment.Right: focusRect = new Rectangle((int)pathRect.Right - 4, (int)pathRect.Y, 4, (int)pathRect.Height); focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Horizontal); break; } // Ensure the focus stip does not go outside the tab Region focusRegion = new Region(focusRect); focusRegion.Intersect(tabpath); graphics.FillRegion(focusBrush, focusRegion); focusRegion.Dispose(); focusBrush.Dispose(); } }
private static void DrawButtonBackground(Graphics g, Rectangle rectangle, bool pressed, bool hovered, bool animating, bool enabled, Color glowColor, float glowOpacity) { SmoothingMode smoothingMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rectangle2 = rectangle; rectangle2.Width--; rectangle2.Height--; rectangle2.X++; rectangle2.Y++; rectangle2.Width -= 2; rectangle2.Height -= 2; Rectangle rectangle3 = rectangle2; rectangle3.Height = rectangle3.Height >> 1; if ((hovered || animating) && !pressed) { using (GraphicsPath path = CreateRoundRectangle(rectangle2, 2)) { g.SetClip(path, CombineMode.Intersect); using (GraphicsPath path2 = CreateBottomRadialPath(rectangle2)) { using (PathGradientBrush brush = new PathGradientBrush(path2)) { int alpha = (int)((178f * glowOpacity) + 0.5f); RectangleF bounds = path2.GetBounds(); brush.CenterPoint = new PointF((bounds.Left + bounds.Right) / 2f, (bounds.Top + bounds.Bottom) / 2f); brush.CenterColor = Color.FromArgb(alpha, glowColor); brush.SurroundColors = new Color[] { Color.FromArgb(0, glowColor) }; g.FillPath(brush, path2); } } g.ResetClip(); } } g.SmoothingMode = smoothingMode; }
private void SetOutline(DockPane pane, DockStyle dock, int contentIndex) { if (dock != DockStyle.Fill) { Rectangle rect = pane.DisplayingRectangle; if (dock == DockStyle.Right) rect.X += rect.Width / 2; if (dock == DockStyle.Bottom) rect.Y += rect.Height / 2; if (dock == DockStyle.Left || dock == DockStyle.Right) rect.Width -= rect.Width / 2; if (dock == DockStyle.Top || dock == DockStyle.Bottom) rect.Height -= rect.Height / 2; rect.Location = pane.PointToScreen(rect.Location); SetDragForm(rect); } else if (contentIndex == -1) { Rectangle rect = pane.DisplayingRectangle; rect.Location = pane.PointToScreen(rect.Location); SetDragForm(rect); } else { using (GraphicsPath path = pane.TabStripControl.GetOutline(contentIndex)) { RectangleF rectF = path.GetBounds(); Rectangle rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height); using (Matrix matrix = new Matrix(rect, new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(0, rect.Height) })) { path.Transform(matrix); } Region region = new Region(path); SetDragForm(rect, region); } } }
public override Boolean IsInRectngle(Rectangle rect, Single xScale, Single yScale) { Point start = new Point(), end = new Point(); start.X = (Int32)(startPoint.X * xScale + rect.X); start.Y = (Int32)(startPoint.Y * yScale + rect.Y); end.X = (Int32)(endPoint.X * xScale + rect.X); end.Y = (Int32)(endPoint.Y * yScale + rect.Y); if (Rotation != 0) { GraphicsPath gp = new GraphicsPath(); Matrix m = new Matrix(); gp.AddLine(start, end); RectangleF pathBounds = gp.GetBounds(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); Boolean ret = true; for (Int32 i = 0; i < 2; i++) { Point p = Point.Truncate(gp.PathPoints[i]); if (!rect.Contains(p)) { ret = false; break; } } gp.Dispose(); return(ret); } else { return(rect.Contains(start) && rect.Contains(end)); } }
/// <summary> /// 根据角度旋转图标 /// </summary> /// <param name="img"></param> private Image RotateImg(Image img, float angle) { //通过Png图片设置图片透明,修改旋转图片变黑问题。 int width = img.Width; int height = img.Height; //角度 Matrix mtrx = new Matrix(); mtrx.RotateAt(angle, new PointF((width / 2), (height / 2)), MatrixOrder.Append); //得到旋转后的矩形 GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, width, height)); RectangleF rct = path.GetBounds(mtrx); //生成目标位图 Bitmap devImage = new Bitmap((int)(rct.Width), (int)(rct.Height)); Graphics g = Graphics.FromImage(devImage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //计算偏移量 Point Offset = new Point((int)(rct.Width - width) / 2, (int)(rct.Height - height) / 2); //构造图像显示区域:让图像的中心与窗口的中心点一致 Rectangle rect = new Rectangle(Offset.X, Offset.Y, (int)width, (int)height); Point center = new Point((int)(rect.X + rect.Width / 2), (int)(rect.Y + rect.Height / 2)); g.TranslateTransform(center.X, center.Y); g.RotateTransform(angle); //恢复图像在水平和垂直方向的平移 g.TranslateTransform(-center.X, -center.Y); g.DrawImage(img, rect); //重至绘图的所有变换 g.ResetTransform(); g.Save(); g.Dispose(); path.Dispose(); return(devImage); }
protected override void DoPage(Graphics grfx, Color clr, int cx, int cy) { GraphicsPath path = new GraphicsPath(); float fFontSize = PointsToPageUnits(grfx, font); // Add text to the path. path.AddString(strText, font.FontFamily, (int)font.Style, fFontSize, new PointF(0, 0), new StringFormat()); // Set the clipping region. grfx.SetClip(path); // Get the path bounds and center the clipping region. RectangleF rectfBounds = path.GetBounds(); grfx.TranslateClip( (cx - rectfBounds.Width) / 2 - rectfBounds.Left, (cy - rectfBounds.Height) / 2 - rectfBounds.Top); // Draw clipped lines. Random rand = new Random(); for (int y = 0; y < cy; y++) { Pen pen = new Pen(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255))); grfx.DrawBezier(pen, new Point(0, y), new Point(cx / 3, y + cy / 3), new Point(2 * cx / 3, y - cy / 3), new Point(cx, y)); } }
private void FillMenuIconGradient( GraphicsPath XFillPath, Graphics g, List <Color> mix ) { using (XAntiAlias xaa = new XAntiAlias(g)) { using (LinearGradientBrush lgb = new LinearGradientBrush (XFillPath.GetBounds(), mix[0], mix[4], LinearGradientMode.Vertical)) { lgb.InterpolationColors = XCoolFormHelper.ColorMix(mix, false); g.FillPath( lgb, XFillPath ); } } }
public PointF CalculateOffset(List <PointF> current, List <PointF> backup) { if (current.Count < 2) { return(PointF.Empty); } //Rect可能发生变化,需要计算偏移 GraphicsPath path = new GraphicsPath(); path.AddLines(current.ToArray()); RectangleF rf = path.GetBounds(); path.Dispose(); NewRect = rf; PointF p1 = Calculation.CalcMatrixPoint(DataBk, PointF.Empty); PointF p2 = Calculation.CalcMatrixPoint(this, PointF.Empty); return(new PointF(p1.X - p2.X, p1.Y - p2.Y)); }
/// <summary> /// Draw rectangle /// </summary> /// <param name="g"></param> public override void Draw(Graphics g) { Pen pen = new Pen(Color); //Brush b = new SolidBrush(Color); //g.DrawString(_theText, _font, b, new PointF(Rectangle.X, Rectangle.Y)); GraphicsPath gp = new GraphicsPath(); StringFormat format = StringFormat.GenericDefault; gp.AddString(_theText, _font.FontFamily, (int)_font.Style, _font.SizeInPoints, new PointF(Rectangle.X, Rectangle.Y), format); // Rotate the path about it's center if necessary if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); rectangle.Size = g.MeasureString(_theText, _font).ToSize(); pen.Dispose(); }
protected override void GeneratePath() { if (points.Count == 0) { //init the polygon, but with coords tha won't be visible right now. _Path = new System.Drawing.Drawing2D.GraphicsPath(); _Path.AddLine(-1000, -1000, -1001, -1001); } else if (points.Count <= 2) { //if the user has established one node, write a dummy command //so the first node will be rendered to the user. _Path = new System.Drawing.Drawing2D.GraphicsPath(); _Path.AddLine(points[0], new Point((int)(points[points.Count - 1].X + 1), (int)points[points.Count - 1].Y)); } else { //refresh the path with the updated points and types _Path = new GraphicsPath(points.ToArray(), types.ToArray()); _Path.CloseAllFigures(); InvalidationArea = Rectangle.Round(_Path.GetBounds()); } }
/* private void updateClock() { lblSongTime.Text = timeToString(coolProgressBar1.Value) + " / " + timeToString(coolProgressBar1.Maximum); lblSongTime.Refresh(); } */ private void RenderText(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; g.CompositingMode = CompositingMode.SourceOver; String text = valueToString(this.Value) + " / " + valueToString(this.Maximum); GraphicsPath stroke = new GraphicsPath(); stroke.AddString(text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); RectangleF bounds = stroke.GetBounds(); /* Align right */ Matrix translationMatrix = new Matrix(); translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, (this.Height - bounds.Height - 5) / 2); stroke.Transform(translationMatrix); g.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */ g.FillPath(Brushes.White, stroke); /* Text */ }