Esempio n. 1
0
		/// <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);
			}
		}
Esempio n. 2
0
		/// <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);
			}
		}
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        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);
        }
        /// <summary>
        /// Draws the stroke of the specified data series points.
        /// </summary>
        /// <param name="dataSeries">The data series.</param>
        /// <param name="points">The points.</param>
        public void DrawSeries(WpfGraphDataSeries dataSeries, IEnumerable <System.Drawing.PointF> points)
        {
            GraphicsPath path = new GraphicsPath();

            path.AddLines(points.ToArray());
            _g.DrawPath(dataSeries.GdiPen, path);
            path.Dispose();
        }
Esempio n. 7
0
        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;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Renders a LineString to the map.
 /// </summary>
 /// <param name="g">Graphics reference</param>
 /// <param name="line">LineString to render</param>
 /// <param name="pen">Pen style used for rendering</param>
 /// <param name="map">Map reference</param>
 public static void DrawLineString(System.Drawing.Graphics g, Geometries.LineString line, System.Drawing.Pen pen, SharpMap.Map map)
 {
     if (line.Vertices.Count > 1)
     {
         System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
         gp.AddLines(line.TransformToImage(map));
         g.DrawPath(pen, gp);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Renders a LineString to the map.
 /// </summary>
 /// <param name="g">Graphics reference</param>
 /// <param name="line">LineString to render</param>
 /// <param name="pen">Pen style used for rendering</param>
 /// <param name="map">Map reference</param>
 public static void DrawLineString(System.Drawing.Graphics g, ILineString line, System.Drawing.Pen pen, SharpMap.Map map)
 {
     if (line.Coordinates.Length > 1)
     {
         System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
         gp.AddLines(Transform.TransformToImage(line, map));
         g.DrawPath(pen, gp);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// CX ÐÂÔö
 /// </summary>
 /// <param name="g"></param>
 /// <param name="line"></param>
 /// <param name="pen"></param>
 /// <param name="map"></param>
 public static void DrawLineString(System.Drawing.Graphics g, Geometries.LineString line, System.Drawing.Pen[] pens, SharpMap.Map map)
 {
     if (line.Vertices.Count > 1)
     {
         GraphicsPath gp = new GraphicsPath();
         gp.AddLines(LimitValues(line.TransformToImage(map), extremeValueLimit));
         for (int i = 0; i < pens.Length; i++)
         {
             g.DrawPath(pens[i], gp);
         }
     }
 }
Esempio n. 11
0
        public void Stroke()
        {
            System.Drawing.Pen p = new System.Drawing.Pen(brush[brush.Count - 1], (float)strokesize[strokesize.Count - 1]);

            if (dashsize[dashsize.Count - 1] > 0)
            {
                p.DashPattern = new float[] { (float)dashsize[dashsize.Count - 1], (float)(dashsize[dashsize.Count - 1] / 2) }
            }
            ;

            graphics.DrawPath(p, path[path.Count - 1]);
            p.Dispose();
        }
Esempio n. 12
0
 public static void DrawRoundedRectangle(this System.Drawing.Graphics graphics, System.Drawing.Pen pen, System.Drawing.Rectangle bounds, int cornerRadius)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (pen == null)
     {
         throw new ArgumentNullException("pen");
     }
     using (System.Drawing.Drawing2D.GraphicsPath path = RoundedRect(bounds, cornerRadius)) {
         graphics.DrawPath(pen, path);
     }
 }
Esempio n. 13
0
        /// <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);
                }
            }
        }
Esempio n. 14
0
        public static void DrawFrame(System.Drawing.Graphics dc, System.Drawing.RectangleF r, float cornerRadius, System.Drawing.Color color)
        {
            var pen = new System.Drawing.Pen(color);

            if (cornerRadius <= 0)
            {
                dc.DrawRectangle(pen, Rect(r));
                return;
            }
            cornerRadius = (float)System.Math.Min(cornerRadius, System.Math.Floor(r.Width) - 2);
            cornerRadius = (float)System.Math.Min(cornerRadius, System.Math.Floor(r.Height) - 2);

            var path = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddArc(r.X, r.Y, cornerRadius, cornerRadius, 180, 90);
            path.AddArc(r.Right - cornerRadius, r.Y, cornerRadius, cornerRadius, 270, 90);
            path.AddArc(r.Right - cornerRadius, r.Bottom - cornerRadius, cornerRadius, cornerRadius, 0, 90);
            path.AddArc(r.X, r.Bottom - cornerRadius, cornerRadius, cornerRadius, 90, 90);
            path.CloseAllFigures();
            dc.DrawPath(pen, path);
        }
Esempio n. 15
0
        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;
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
 public void DisplayOn(System.Drawing.Graphics g)
 {
     g.DrawPath(System.Drawing.Pens.DarkRed, _Path);
 }
Esempio n. 18
0
        public void DrawRoundedRect(float x, float y, float width, float height, float radius, float w)
        {
            var path = CreateRoundedRectPath(x, y, width, height, radius);

            g.DrawPath(color.GetPen(w), path);
        }
Esempio n. 19
0
        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));
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        private void ListView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var item = listView.SelectedItem as Record;

            if (!listView.HasItems || item.EventMouse == null)
            {
                return;
            }
            try
            {
                if (g != null)
                {
                    RedrawWindow(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
                    g.Dispose();
                    //ReleaseDC(desktop);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            int id = item.Id;

            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 3);

            if (item.EventMouse.Action == MouseHook.MouseEvents.MouseMove)
            {
                Record last = recordList.FindLast(r =>
                {
                    if (r.EventMouse == null)
                    {
                        return(false);
                    }
                    return(r.Id < id && r.EventMouse.Action != MouseHook.MouseEvents.MouseMove);
                });
                if (last == null)
                {
                    last = recordList[0];
                }
                List <Record> list = recordList.FindAll(r => r.Id <= id && r.Id > last.Id);

                desktop = GetDC(IntPtr.Zero);
                g       = System.Drawing.Graphics.FromHdc(desktop);
                System.Drawing.Point[] points = list.ConvertAll(new Converter <Record, System.Drawing.Point>(RecordToPoint)).ToArray();
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddLines(points);
                g.DrawPath(pen, path);
                //g.Clear(System.Drawing.Color.Transparent);
            }
            else if (item.Type == Constants.MOUSE)
            {
                int lengthLine = 40;
                desktop = GetDC(IntPtr.Zero);
                g       = System.Drawing.Graphics.FromHdc(desktop);
                System.Drawing.Point point1 = new System.Drawing.Point(
                    (int)item.EventMouse.Location.X, (int)item.EventMouse.Location.Y - lengthLine);
                System.Drawing.Point point2 = new System.Drawing.Point(
                    (int)item.EventMouse.Location.X, (int)item.EventMouse.Location.Y + lengthLine);
                g.DrawLine(pen, point1, point2);

                System.Drawing.Point point3 = new System.Drawing.Point(
                    (int)item.EventMouse.Location.X - lengthLine, (int)item.EventMouse.Location.Y);
                System.Drawing.Point point4 = new System.Drawing.Point(
                    (int)item.EventMouse.Location.X + lengthLine, (int)item.EventMouse.Location.Y);

                g.DrawLine(pen, point3, point4);
            }
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        public static byte[] GetWarpCaptcha()
        {
            byte[] imageBytes = null;

            string text = "I can haz Peanut";

            text = "This is a test";
            text = Helpers.GenerateRandomCode();
            text = Helpers.GenerateRandomNumber();

            System.Drawing.Drawing2D.GraphicsPath textPath = new System.Drawing.Drawing2D.GraphicsPath();

            float fontSize = 23;

            // textPath.AddString("st", null, 123, 12, )

            // the baseline should start at 0,0, so the next line is not quite correct
            textPath.AddString(
                text
                , System.Drawing.FontFamily.GenericSansSerif
                , (int)System.Drawing.FontStyle.Bold, fontSize
                , new System.Drawing.Point(0, 0)
                , System.Drawing.StringFormat.GenericTypographic
                );

            System.Drawing.RectangleF textBounds = textPath.GetBounds();


            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(300, 150))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.Clear(System.Drawing.Color.White);

                    System.Drawing.Drawing2D.HatchBrush hatchBrush =
                        new System.Drawing.Drawing2D.HatchBrush(
                            //System.Drawing.Drawing2D.HatchStyle.SmallConfetti
                            System.Drawing.Drawing2D.HatchStyle.Wave
                            //System.Drawing.Drawing2D.HatchStyle.Plaid
                            , System.Drawing.Color.LightGray
                            //, System.Drawing.Color.Black
                            , System.Drawing.Color.White
                            );
                    g.FillRectangle(hatchBrush, 0, 0, bmp.Width, bmp.Height);


                    // GraphicsPath bezierPath = textPath;
                    // GraphicsPath bezierPath = BezierWarp(textPath, new System.Drawing.Size((int)textBounds.Width, (int)textBounds.Height));
                    System.Drawing.Drawing2D.GraphicsPath bezierPath = BezierWarp(textPath, new System.Drawing.Size(bmp.Width, bmp.Height));

                    // draw the transformed text path
                    g.DrawPath(System.Drawing.Pens.Black, bezierPath);

                    // Draw the Bézier for reference
                    // g.DrawBezier(Pens.Black, P0, P1, P2, P3);
                } // End Using g

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imageBytes = ms.ToArray();
                } // End Using ms
            }     // End Using bmp

            return(imageBytes);
        } // End Function GetWarpCaptcha
Esempio n. 24
0
        /// <summary>
        /// Draw border at specified position.
        /// </summary>
        /// <param name="g">Instance for graphics object.</param>
        /// <param name="x">X coordinate of start point.</param>
        /// <param name="y">Y coordinate of start point.</param>
        /// <param name="x2">X coordinate of end point.</param>
        /// <param name="y2">Y coordinate of end point.</param>
        /// <param name="style">Style flag of border.</param>
        /// <param name="color">Color of border.</param>
        /// <param name="bgPen">Fill pen used when drawing double outline.</param>
        public void DrawLine(PlatformGraphics g, RGFloat x, RGFloat y, RGFloat x2, RGFloat y2, BorderLineStyle style,
                             SolidColor color, RGPen bgPen = null)
        {
            if (style == BorderLineStyle.None)
            {
                return;
            }

#if WINFORM || WPF || ANDROID
#if WINFORM
            RGPen p = pens[(byte)style];

            lock (p)
            {
                p.Color    = color;
                p.StartCap = System.Drawing.Drawing2D.LineCap.Square;
                p.EndCap   = System.Drawing.Drawing2D.LineCap.Square;
                g.DrawLine(p, new RGPointF(x, y), new RGPointF(x2, y2));
            }
#elif WPF
            // get template pen from cache list
            var tp = pens[(byte)style];

            // create new WPF pen
            var p = new RGPen(new RGSolidBrush(color), tp.Thickness);
            // copy the pen style from template
            p.DashStyle = tp.DashStyle;

            p.StartLineCap = System.Windows.Media.PenLineCap.Square;
            p.EndLineCap   = System.Windows.Media.PenLineCap.Square;

            System.Windows.Media.GuidelineSet gs = new System.Windows.Media.GuidelineSet();
            double halfPenWidth = p.Thickness / 2;
            gs.GuidelinesX.Add(x + halfPenWidth);
            gs.GuidelinesY.Add(y + halfPenWidth);
            gs.GuidelinesX.Add(x2 + halfPenWidth);
            gs.GuidelinesY.Add(y2 + halfPenWidth);
            g.PushGuidelineSet(gs);
            g.DrawLine(p, new RGPointF(x, y), new RGPointF(x2, y2));
#elif ANDROID
            g.DrawLine(x, y, x2, y2, p);
#endif



            if (style == BorderLineStyle.DoubleLine && bgPen != null)
            {
                lock (bgPen)
                {
#if WINFORM || WPF
                    g.DrawLine(bgPen, new RGPointF(x, y), new RGPointF(x2, y2));
#elif ANDROID
                    g.DrawLine(x, y, x2, y2, bgPen);
#endif // WPF
                }
            }

#if WPF
            g.Pop();
#endif // WPF

//#endif // WINFORM || WPF || ANDROID
#elif iOS
            using (var path = new CGPath())
            {
                path.AddLines(new CGPoint[] { new CGPoint(x, y), new CGPoint(x2, y2) });

                switch (style)
                {
                default:
                case BorderLineStyle.Solid:
                    g.AddPath(path);
                    g.SetStrokeColor(color);
                    g.DrawPath(CGPathDrawingMode.Stroke);
                    break;
                }
            }
#endif // iOS
        }
Esempio n. 25
0
        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;
            }
        }