/// <summary> /// Renders a label to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="LabelPoint">Label placement</param> /// <param name="Offset">Offset of label in screen coordinates</param> /// <param name="font">Font used for rendering</param> /// <param name="forecolor">Font forecolor</param> /// <param name="backcolor">Background color</param> /// <param name="halo">Color of halo</param> /// <param name="rotation">Text rotation in degrees</param> /// <param name="text">Text to render</param> /// <param name="map">Map reference</param> public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, SharpMap.Map map) { System.Drawing.SizeF fontSize = g.MeasureString(text, font); //Calculate the size of the text LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y; //add label offset if (rotation != 0 && rotation != float.NaN) { g.TranslateTransform(LabelPoint.X, LabelPoint.Y); g.RotateTransform(rotation); g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2); if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent) g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null); if (halo != null) g.DrawPath(halo, path); g.FillPath(new System.Drawing.SolidBrush(forecolor), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0); g.Transform = map.MapTransform; } else { if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent) g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null); if (halo != null) g.DrawPath(halo, path); g.FillPath(new System.Drawing.SolidBrush(forecolor), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y); } }
public override void Draw(System.Drawing.Graphics g, ICoordinateMapper coordinateMapper) { if (g == null) { throw new System.ArgumentNullException("g"); } if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } if (!base.Enabled || _path == null) { return; } System.Drawing.Point drawPnt = coordinateMapper.WorkspaceToControl(base.Location, Aurigma.GraphicsMill.Unit.Point); using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1.0f, 0.0f, 0.0f, 1.0f, drawPnt.X, drawPnt.Y)) { g.Transform = m; if (_brush != null) { g.FillPath(_brush, _path); } if (this.Pen != null) { g.DrawPath(_pen, _path); } g.Transform = new System.Drawing.Drawing2D.Matrix(); } }
public static void drawGraphics(List <double> xs, List <double> ys, double w_height, System.Windows.Forms.Panel panel) { double maxX = xs.Max(); double maxY = ys.Max(); double width = maxX - xs.Min(); double maxheight = maxY - ys.Min(); double xscale = panel.Width / width; double yscale = panel.Height / maxheight; System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Tan, 3); System.Drawing.SolidBrush waterFill = new System.Drawing.SolidBrush(System.Drawing.Color.AliceBlue); System.Drawing.Graphics crossSection = panel.CreateGraphics(); crossSection.ScaleTransform((float)xscale, (float)yscale); System.Drawing.PointF[] points = new System.Drawing.PointF[xs.Count]; for (int i = 0; i < xs.Count - 1; i++) { double y = maxY - ys[i]; double y2 = maxY - ys[i + 1]; double x = xs[i]; points[i] = new System.Drawing.PointF((float)x, (float)y); } byte[] types = { (byte)points[0].X, (byte)System.Drawing.Drawing2D.PathPointType.Line, (byte)System.Drawing.Drawing2D.PathPointType.DashMode }; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(points, types, System.Drawing.Drawing2D.FillMode.Alternate); crossSection.DrawPath(pen, path); crossSection.FillPath(waterFill, path); }
public void FillRoundedRect(float x, float y, float width, float height, float radius) { var rect = new System.Drawing.RectangleF(x, y, width, height); var path = CreateRoundedRectPath(x, y, width, height, radius); g.FillPath(GetBrush(rect), path); }
/// <summary> /// Renders a polygon to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="pol">Polygon to render</param> /// <param name="brush">Brush used for filling (null or transparent for no filling)</param> /// <param name="pen">Outline pen style (null if no outline)</param> /// <param name="clip">Specifies whether polygon clipping should be applied</param> /// <param name="map">Map reference</param> public static void DrawPolygon(System.Drawing.Graphics g, SharpMap.Geometries.Polygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map) { if (pol.ExteriorRing == null) return; if (pol.ExteriorRing.Vertices.Count > 2) { //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); //Add the exterior polygon if (!clip) gp.AddPolygon(pol.ExteriorRing.TransformToImage(map)); else gp.AddPolygon(clipPolygon(pol.ExteriorRing.TransformToImage(map), map.Size.Width, map.Size.Height)); //Add the interior polygons (holes) for (int i = 0; i < pol.InteriorRings.Count; i++) if (!clip) gp.AddPolygon(pol.InteriorRings[i].TransformToImage(map)); else gp.AddPolygon(clipPolygon(pol.InteriorRings[i].TransformToImage(map), map.Size.Width, map.Size.Height)); // Only render inside of polygon if the brush isn't null or isn't transparent if (brush != null && brush != System.Drawing.Brushes.Transparent) g.FillPath(brush, gp); // Create an outline if a pen style is available if (pen != null) g.DrawPath(pen, gp); } }
public static void Draw(System.Drawing.Graphics gr, int x, int y, int size) { GraphicsPath gp = Make_Path(x, y, size); gr.FillPath(PensBrushes.redbrush, gp); gr.DrawPath(PensBrushes.black_pen, gp); }
public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper) { if (g == null) { throw new System.ArgumentNullException("g"); } if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } System.Drawing.Drawing2D.GraphicsPath drawPath = CreateViewportPath(coordinateMapper); System.Drawing.Pen pen = CreateViewportPen(coordinateMapper); System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = g.SmoothingMode; try { switch (base.DrawMode) { case VObjectDrawMode.Draft: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; break; case VObjectDrawMode.Normal: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; break; default: throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrUnexpectedDrawMode")); } if (_brush != null) { AdaptBrushToViewport(coordinateMapper); try { g.FillPath(_brush, drawPath); } finally { RestoreBrush(); } } if (pen != null) { g.DrawPath(pen, drawPath); } } finally { if (pen != null) { pen.Dispose(); } drawPath.Dispose(); g.SmoothingMode = oldSmoothingMode; } }
public static void FillRoundedRectangle(this System.Drawing.Graphics graphics, System.Drawing.Brush brush, System.Drawing.Rectangle bounds, int cornerRadius) { if (graphics == null) { throw new ArgumentNullException("graphics"); } if (brush == null) { throw new ArgumentNullException("brush"); } using (System.Drawing.Drawing2D.GraphicsPath path = RoundedRect(bounds, cornerRadius)) { graphics.FillPath(brush, path); } }
/// <summary> /// Renders a polygon to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="pol">Polygon to render</param> /// <param name="brush">Brush used for filling (null or transparent for no filling)</param> /// <param name="pen">Outline pen style (null if no outline)</param> /// <param name="clip">Specifies whether polygon clipping should be applied</param> /// <param name="map">Map reference</param> public static void DrawPolygon(System.Drawing.Graphics g, IPolygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map) { if (pol.Shell == null) { return; } if (pol.Shell.Coordinates.Length > 2) { //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); //Add the exterior polygon if (!clip) { gp.AddPolygon(Transform.TransformToImage(pol.Shell, map)); } else { gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Shell, map), map.Size.Width, map.Size.Height)); } //Add the interior polygons (holes) for (int i = 0; i < pol.Holes.Length; i++) { if (!clip) { gp.AddPolygon(Transform.TransformToImage(pol.Holes[i], map)); } else { gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Holes[i], map), map.Size.Width, map.Size.Height)); } } // Only render inside of polygon if the brush isn't null or isn't transparent if (brush != null && brush != System.Drawing.Brushes.Transparent) { g.FillPath(brush, gp); } // Create an outline if a pen style is available if (pen != null) { g.DrawPath(pen, gp); } } }
public System.Drawing.Image RoundCorners(BitmapImage StartImage, int CornerRadius, System.Drawing.Color BackgroundColor) { System.Drawing.Image img = System.Drawing.Image.FromFile(StartImage.UriSource.LocalPath); CornerRadius *= 2; System.Drawing.Bitmap RoundedImage = new System.Drawing.Bitmap(img.Width, img.Height); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(RoundedImage)) { g.Clear(BackgroundColor); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; System.Drawing.Brush brush = new System.Drawing.TextureBrush(img); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddArc(0, 0, CornerRadius, CornerRadius, 180, 90); gp.AddArc(0 + RoundedImage.Width - CornerRadius, 0, CornerRadius, CornerRadius, 270, 90); gp.AddArc(0 + RoundedImage.Width - CornerRadius, 0 + RoundedImage.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); gp.AddArc(0, 0 + RoundedImage.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); g.FillPath(brush, gp); return(RoundedImage); } }
public System.Drawing.Bitmap GenerateMap(System.Drawing.Bitmap background = null) { int minx = int.MaxValue; int maxx = int.MinValue; int miny = int.MaxValue; int maxy = int.MinValue; int minz = int.MaxValue; int maxz = int.MinValue; foreach (var spd in SearchPointDefinitions) { minx = Math.Min(minx, spd.CoordX); miny = Math.Min(miny, spd.CoordY); minz = Math.Min(minz, spd.CoordZ); maxx = Math.Max(maxx, spd.CoordX); maxy = Math.Max(maxy, spd.CoordY); maxz = Math.Max(maxz, spd.CoordZ); } int extentx = maxx - minx; int extenty = maxy - miny; int extentz = maxz - minz; double factor = 0.05115; int padx = 222; int pady = 185; System.Drawing.Bitmap bmp; if (background == null) { bmp = new System.Drawing.Bitmap((int)(extentx * factor + 1 + padx * 2), (int)(extentz * factor + 1 + pady * 2)); } else { bmp = new System.Drawing.Bitmap(background); } int idx = 1; foreach (var spd in SearchPointDefinitions) { if (spd.Unknown11 != 1) { continue; } // not sure what these mean exactly but only the ones with an '1' here show up in game System.Drawing.Color color = System.Drawing.Color.Black; System.Drawing.Color border = System.Drawing.Color.White; switch (spd.SearchPointType) { case 0: color = System.Drawing.Color.SpringGreen; border = System.Drawing.Color.Black; break; // tree stump case 1: // shells if (spd.CoordY < 0) { color = System.Drawing.Color.Red; // in water border = System.Drawing.Color.White; } else { color = System.Drawing.Color.Aqua; // on beach border = System.Drawing.Color.Black; } break; case 2: color = System.Drawing.Color.FromArgb(212, 212, 0); border = System.Drawing.Color.Black; break; // bones case 3: color = System.Drawing.Color.DarkBlue; border = System.Drawing.Color.White; break; // seagulls } //SetPixelArea( bmp, (int)( ( spd.CoordX - minx ) * factor + padx ), (int)( ( extentz - ( spd.CoordZ - minz ) ) * factor + pady ), color, border ); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; System.Drawing.StringFormat fmt = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoClip) { Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center }; //System.Drawing.Font font = new System.Drawing.Font( "Gentium Book", 32.0f, System.Drawing.GraphicsUnit.Pixel ); int x = (int)((spd.CoordX - minx) * factor + padx); int y = (int)((extentz - (spd.CoordZ - minz)) * factor + pady); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(idx.ToString(), new System.Drawing.FontFamily("Gentium Book"), (int)System.Drawing.FontStyle.Regular, 80.0f, new System.Drawing.Point(x, y + 4), fmt); g.DrawPath(new System.Drawing.Pen(border, 8), path); g.FillPath(new System.Drawing.SolidBrush(color), path); g.Flush(); ++idx; } return(bmp); }
private void GenerateImage() { System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap (this.width, this.height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, this.width, this.height); System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.SmallConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.White); g.FillRectangle(hatchBrush, rect); System.Drawing.SizeF size; float fontSize = rect.Height + 1; System.Drawing.Font font; do { fontSize--; font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, fontSize, System.Drawing.FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); System.Drawing.StringFormat format = new System.Drawing.StringFormat(); format.Alignment = System.Drawing.StringAlignment.Center; format.LineAlignment = System.Drawing.StringAlignment.Center; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(this.text, font.FontFamily, (int)font.Style, 75, rect, format); float v = 4F; System.Drawing.PointF[] points = { new System.Drawing.PointF(this.random.Next(rect.Width) / v, this.random.Next( rect.Height) / v), new System.Drawing.PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new System.Drawing.PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new System.Drawing.PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0F); hatchBrush = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.Percent10 , System.Drawing.Color.Black, System.Drawing.Color.SkyBlue); g.FillPath(hatchBrush, path); int m = System.Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }
private SharpDX.Direct2D1.Bitmap DrawString(int width, int height, float fontSize15, float fontSize30) { //Dont know how to draw this on SharpDx so i'm using system drawing to draw and convet it to SharpDX Bitmap. System.Drawing.Graphics gr = System.Drawing.Graphics.FromHwnd(IntPtr.Zero); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(width, height, gr); gr.Dispose(); gr = System.Drawing.Graphics.FromImage(bm); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); var strformat = new System.Drawing.StringFormat { Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center }; gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; if (PlayerControl.Text_Intro == string.Empty || PlayerControl.Text_Intro == null) { string b = "BossDoy KaraokeNow"; var stringSize = MeasureString(b, fontSize15); path.AddString(b, fontFamily, (int)System.Drawing.FontStyle.Bold, fontSize15, new System.Drawing.Point((bm.Width / 2), (bm.Height / 2) - ((int)stringSize.Height) / 2), strformat); path.AddString("Select a song", fontFamily, (int)System.Drawing.FontStyle.Bold, fontSize30, new System.Drawing.Point(bm.Width / 2, (bm.Height / 2) + ((int)stringSize.Height) / 2), strformat); } else { string[] intro = PlayerControl.Text_Intro.Split(new char[] { '@' }, StringSplitOptions.None); var stringSize = MeasureString(intro[0], fontSize15); path.AddString(intro[0], fontFamily, (int)System.Drawing.FontStyle.Bold, fontSize15, new System.Drawing.Point((bm.Width / 2), (bm.Height / 2) - ((int)stringSize.Height) / 2), strformat); if (intro.Length > 1) { path.AddString(intro[1], fontFamily, (int)System.Drawing.FontStyle.Bold, fontSize30, new System.Drawing.Point(bm.Width / 2, (bm.Height / 2) + ((int)stringSize.Height) / 2), strformat); } else { path.AddString("Select a song", fontFamily, (int)System.Drawing.FontStyle.Bold, fontSize30, new System.Drawing.Point(bm.Width / 2, (bm.Height / 2) + ((int)stringSize.Height) / 2), strformat); } } System.Drawing.Pen penOut = new System.Drawing.Pen(System.Drawing.Color.FromArgb(32, 117, 81), (fontSize30 / 4)); penOut.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gr.DrawPath(penOut, path); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(234, 137, 6), (fontSize30 / 8)); pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gr.DrawPath(pen, path); System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 0, 255)); gr.FillPath(brush, path); path.Dispose(); penOut.Dispose(); pen.Dispose(); brush.Dispose(); gr.Dispose(); return(ConvertToSharpDXBitmap(m_D2DContext.d2dContext, bm)); }
public void Fill() { graphics.FillPath(brush[brush.Count - 1], path[path.Count - 1]); }
public static void Draw( DelaunatorSharp.Delaunator delaunay , DelaunatorSharp.IPoint[] points , BoundingBox bbox , Circumcircles circumcircles , System.Drawing.Graphics ctx , float padding , float scale , FlatQueue <float> queue , bool[] onEdge ) { // ctx.clearRect(0, 0, width, height); ctx.Clear(System.Drawing.Color.White); System.Drawing.Drawing2D.GraphicsPath path1 = new System.Drawing.Drawing2D.GraphicsPath(); int[] t = delaunay.Triangles; for (int i = 0; i < t.Length; i += 3) { DelaunatorSharp.IPoint pt1 = points[t[i + 0]]; float ax = (float)pt1.X; float ay = (float)pt1.Y; DelaunatorSharp.IPoint pt2 = points[t[i + 1]]; float bx = (float)pt2.X; float by = (float)pt2.Y; DelaunatorSharp.IPoint pt3 = points[t[i + 2]]; float cx = (float)pt3.X; float cy = (float)pt3.Y; path1.StartFigure(); path1.AddLine(projX(ax, padding, scale, bbox), projY(ay, padding, scale, bbox), projX(bx, padding, scale, bbox), projY(by, padding, scale, bbox)); path1.AddLine(projX(bx, padding, scale, bbox), projY(by, padding, scale, bbox), projX(cx, padding, scale, bbox), projY(cy, padding, scale, bbox)); path1.CloseFigure(); } System.Drawing.Pen trianglePen = new System.Drawing.Pen(System.Drawing.Color.FromArgb((int)(0.4 * 255), 0, 200, 0)); trianglePen.Width = 0.5f; trianglePen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; ctx.DrawPath(trianglePen, path1); System.Drawing.Drawing2D.GraphicsPath path2 = new System.Drawing.Drawing2D.GraphicsPath(); // for (const [x, y] of points) foreach (DelaunatorSharp.IPoint thisPoint in points) { float sx = projX((float)thisPoint.X, padding, scale, bbox); float sy = projY((float)thisPoint.Y, padding, scale, bbox); float r = 1.5f; r = 5; path2.StartFigure(); path2.AddArc(sx - r / 2.0f, sy - r / 2.0f, r, r, 0.0f, 360.0f); path2.CloseFigure(); } System.Drawing.Brush blackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); ctx.FillPath(blackBrush, path2); // ctx.beginPath(); System.Drawing.Drawing2D.GraphicsPath path3 = new System.Drawing.Drawing2D.GraphicsPath(); // path3.StartFigure(); for (int i = 0; i < onEdge.Length; i++) { if (!onEdge[i]) { continue; } DelaunatorSharp.IPoint pt1 = points[t[i]]; float ax = (float)pt1.X; float ay = (float)pt1.Y; DelaunatorSharp.IPoint pt2 = points[t[i % 3 == 2 ? i - 2 : i + 1]]; float bx = (float)pt2.X; float by = (float)pt2.Y; path3.StartFigure(); path3.AddLine(projX(ax, padding, scale, bbox), projY(ay, padding, scale, bbox), projX(bx, padding, scale, bbox), projY(by, padding, scale, bbox)); path3.CloseFigure(); // ctx.moveTo(projX(ax), projY(ay)); // ctx.lineTo(projX(bx), projY(by)); // ctx.closePath(); } // path3.CloseFigure(); System.Drawing.Pen hullPen = new System.Drawing.Pen(System.Drawing.Color.Blue); hullPen.Width = 2.0f; ctx.DrawPath(hullPen, path3); System.Drawing.Drawing2D.GraphicsPath path4 = new System.Drawing.Drawing2D.GraphicsPath(); foreach (int i in queue.ids) { // ctx.beginPath(); path4.StartFigure(); float sr = circumcircles.r[i] * scale; float sx = projX(circumcircles.x[i], padding, scale, bbox); float sy = projY(circumcircles.y[i], padding, scale, bbox); //ctx.moveTo(sx + sr, sy); //ctx.arc(sx, sy, sr, 0, Math.PI* 2, false); //ctx.strokeStyle = 'rgba(200,0,0,1)'; //ctx.lineWidth = 1; //ctx.stroke(); //ctx.fillStyle = 'rgba(255,255,0,0.2)'; //ctx.fill(); path4.AddArc(sx - sr / 2.0f, sy - sr / 2.0f, sr, sr, 0.0f, 360.0f); path4.CloseFigure(); } System.Drawing.SolidBrush circleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb((int)(0.2 * 255), 255, 255, 0)); System.Drawing.Pen redCircle = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 200, 0, 0)); redCircle.Width = 1; redCircle.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; ctx.FillPath(circleBrush, path4); ctx.DrawPath(redCircle, path4); }
private void doRender(object sender, DoWorkEventArgs e) { var polygons = this.Polygons; if (!(polygons?.Any() ?? false)) { _image.Source = null; return; } _width = _layer.Map.Size.Width; _height = _layer.Map.Size.Height; initialize(); if (this.IsDirty || _paths == null) { var paths = new Dictionary <PolygonObject, IEnumerable <System.Drawing.Drawing2D.GraphicsPath> >(); foreach (var item in polygons) { var polygonPaths = new List <System.Drawing.Drawing2D.GraphicsPath>(); foreach (var pixelPoints in item.Value.PixelPoints) { var path = new System.Drawing.Drawing2D.GraphicsPath() { FillMode = System.Drawing.Drawing2D.FillMode.Alternate }; var points = pixelPoints.Select(p => p.AsGdiPointF()).ToArray(); if (_layer.UseCurvedLines) { path.AddCurve(points); } else { path.AddLines(points); } polygonPaths.Add(path); } paths[item.Value] = polygonPaths; } _paths = paths; this.IsDirty = false; } var pen = _layer.StrokeColor != null && _layer.StrokeColor != Colors.Transparent && _layer.StrokeThickness > 0 ? new System.Drawing.Pen(_layer.StrokeColor.AsGdiBrush(), (float)_layer.StrokeThickness) : null; foreach (var item in _paths) { foreach (var path in item.Value) { try { var fill = item.Key.Fill != null && item.Key.Fill != Colors.Transparent ? item.Key.Fill.AsGdiBrush() : null; if (fill != null) { _gdiGraphics.FillPath(fill, path); } if (pen != null) { _gdiGraphics.DrawPath(pen, path); } } catch { } } } _interopBitmap.Invalidate(); _interopBitmap.Freeze(); e.Result = _interopBitmap; }
// ==================================================================== // Creates the bitmap image. // ==================================================================== private void GenerateImage() { // Create a new 32-bit bitmap image. System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(this.width, this.height , System.Drawing.Imaging.PixelFormat.Format32bppArgb); // Create a graphics object for drawing. System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, this.width, this.height); // Fill in the background. System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.SmallConfetti , System.Drawing.Color.LightGray , System.Drawing.Color.White); g.FillRectangle(hatchBrush, rect); // Set up the text font. System.Drawing.SizeF size; float fontSize = rect.Height + 1; System.Drawing.Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new System.Drawing.Font(this.familyName, fontSize, System.Drawing.FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); // Set up the text format. System.Drawing.StringFormat format = new System.Drawing.StringFormat(); format.Alignment = System.Drawing.StringAlignment.Center; format.LineAlignment = System.Drawing.StringAlignment.Center; // Create a path using the text and warp it randomly. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; System.Drawing.PointF[] points = { new System.Drawing.PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new System.Drawing.PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new System.Drawing.PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new System.Drawing.PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.LargeConfetti , System.Drawing.Color.LightGray , System.Drawing.Color.DarkGray); g.FillPath(hatchBrush, path); // Add some random noise. int m = System.Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; }
public static void Run() { // ExStart:ExtractBorder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); Document doc = new Document(dataDir + "input.pdf"); Stack graphicsState = new Stack(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)doc.Pages[1].PageInfo.Width, (int)doc.Pages[1].PageInfo.Height); System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); // Default ctm matrix value is 1,0,0,1,0,0 System.Drawing.Drawing2D.Matrix lastCTM = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 0); // System.Drawing coordinate system is top left based, while pdf coordinate system is low left based, so we have to apply the inversion matrix System.Drawing.Drawing2D.Matrix inversionMatrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, (float)doc.Pages[1].PageInfo.Height); System.Drawing.PointF lastPoint = new System.Drawing.PointF(0, 0); System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 0, 0); System.Drawing.Color strokeColor = System.Drawing.Color.FromArgb(0, 0, 0); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bitmap)) { gr.SmoothingMode = SmoothingMode.HighQuality; graphicsState.Push(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0)); // Process all the contents commands foreach (Operator op in doc.Pages[1].Contents) { Operator.GSave opSaveState = op as Operator.GSave; Operator.GRestore opRestoreState = op as Operator.GRestore; Operator.ConcatenateMatrix opCtm = op as Operator.ConcatenateMatrix; Operator.MoveTo opMoveTo = op as Operator.MoveTo; Operator.LineTo opLineTo = op as Operator.LineTo; Operator.Re opRe = op as Operator.Re; Operator.EndPath opEndPath = op as Operator.EndPath; Operator.Stroke opStroke = op as Operator.Stroke; Operator.Fill opFill = op as Operator.Fill; Operator.EOFill opEOFill = op as Operator.EOFill; Operator.SetRGBColor opRGBFillColor = op as Operator.SetRGBColor; Operator.SetRGBColorStroke opRGBStrokeColor = op as Operator.SetRGBColorStroke; if (opSaveState != null) { // Save previous state and push current state to the top of the stack graphicsState.Push(((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Clone()); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opRestoreState != null) { // Throw away current state and restore previous one graphicsState.Pop(); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opCtm != null) { System.Drawing.Drawing2D.Matrix cm = new System.Drawing.Drawing2D.Matrix( (float)opCtm.Matrix.A, (float)opCtm.Matrix.B, (float)opCtm.Matrix.C, (float)opCtm.Matrix.D, (float)opCtm.Matrix.E, (float)opCtm.Matrix.F); // Multiply current matrix with the state matrix ((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Multiply(cm); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opMoveTo != null) { lastPoint = new System.Drawing.PointF((float)opMoveTo.X, (float)opMoveTo.Y); } else if (opLineTo != null) { System.Drawing.PointF linePoint = new System.Drawing.PointF((float)opLineTo.X, (float)opLineTo.Y); graphicsPath.AddLine(lastPoint, linePoint); lastPoint = linePoint; } else if (opRe != null) { System.Drawing.RectangleF re = new System.Drawing.RectangleF((float)opRe.X, (float)opRe.Y, (float)opRe.Width, (float)opRe.Height); graphicsPath.AddRectangle(re); } else if (opEndPath != null) { graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opRGBFillColor != null) { fillColor = opRGBFillColor.getColor(); } else if (opRGBStrokeColor != null) { strokeColor = opRGBStrokeColor.getColor(); } else if (opStroke != null) { graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.DrawPath(new System.Drawing.Pen(strokeColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opFill != null) { graphicsPath.FillMode = FillMode.Winding; graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opEOFill != null) { graphicsPath.FillMode = FillMode.Alternate; graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } } } dataDir = dataDir + "ExtractBorder_out_.png"; bitmap.Save(dataDir, ImageFormat.Png); // ExEnd:ExtractBorder Console.WriteLine("\nBorder extracted successfully as image.\nFile saved at " + dataDir); }
private void DrawText() { try { if (fontItem == null) { this.imgFont.Source = null; return; } System.Drawing.Font fontText = new System.Drawing.Font(fontItem.FontName, fontItem.FontSize); System.Drawing.Size sizeText = System.Windows.Forms.TextRenderer.MeasureText(fontItem.Text, fontText, new System.Drawing.Size(0, 0), System.Windows.Forms.TextFormatFlags.NoPadding); Rect viewport = new Rect(0, 0, sizeText.Width, sizeText.Height); if ((int)viewport.Width == 0 || (int)viewport.Height == 0) { return; } System.Drawing.Bitmap tempMap = new System.Drawing.Bitmap((int)viewport.Width, (int)viewport.Height); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(tempMap); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0, sizeText.Width, sizeText.Height); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(fontItem.Text, fontText.FontFamily, (int)fontText.Style, fontText.Size, rect, System.Drawing.StringFormat.GenericDefault); //描边 g.DrawPath(new System.Drawing.Pen(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(fontItem.StrokeColor.A, fontItem.StrokeColor.R, fontItem.StrokeColor.G, fontItem.StrokeColor.B)), fontItem.StrokeColorLength), path); //颜色 g.FillPath(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(fontItem.FontColor.A, fontItem.FontColor.R, fontItem.FontColor.G, fontItem.FontColor.B)), path); //渐变 g.FillPath(new System.Drawing.Drawing2D.LinearGradientBrush(rect, System.Drawing.Color.FromArgb(fontItem.GradientColor1.A, fontItem.GradientColor1.R, fontItem.GradientColor1.G, fontItem.GradientColor1.B), System.Drawing.Color.FromArgb(fontItem.GradientColor2.A, fontItem.GradientColor2.R, fontItem.GradientColor2.G, fontItem.GradientColor2.B), System.Drawing.Drawing2D.LinearGradientMode.Vertical), path); //图片叠加 if (fontItem.OverlayImage != null) { System.Drawing.TextureBrush brush = new System.Drawing.TextureBrush(ImageHelper.BitmapImageToIamge(fontItem.OverlayImage), System.Drawing.Drawing2D.WrapMode.TileFlipXY);//可改变渐变方式 g.FillPath(brush, path); } path.Dispose(); BitmapImage tempImage = ImageHelper.BitmapToBitmapImage(tempMap, System.Drawing.Imaging.ImageFormat.Png); g.Dispose(); tempMap.Dispose(); if (tempImage != null) { this.imgFont.Source = tempImage; this.imgFont.Width = tempImage.Width; this.imgFont.Height = tempImage.Height; Canvas.SetLeft(this.imgFont, (this.mainCanvas.ActualWidth - tempImage.Width) / 2); Canvas.SetTop(this.imgFont, (this.mainCanvas.ActualHeight - tempImage.Height) / 2); } } catch (Exception ex) { return; } }