Dispose() публичный Метод

public Dispose ( bool disposing ) : void
disposing bool
Результат void
Пример #1
0
 /// <summary>
 /// Instructs the drawing code to fill the specified path with the specified pattern
 /// </summary>
 /// <param name="g">The System.Drawing.Graphics device to draw to</param>
 /// <param name="gp">The System.Drawing.Drawing2D.GraphicsPath to fill</param>
 public override void FillPath(Graphics g, GraphicsPath gp)
 {
     System.Drawing.Drawing2D.HatchBrush hb = new HatchBrush(_hatchStyle, _foreColor, _backColor);
     g.FillPath(hb, gp);
     hb.Dispose();
     base.FillPath(g, gp);
 }
Пример #2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            e.DrawBackground();

            HatchStyle style = FromString((string)this.Items[e.Index]);

            System.Drawing.Drawing2D.HatchBrush brush =
                new System.Drawing.Drawing2D.HatchBrush(style, Color.Black, e.BackColor);
            System.Drawing.Pen pen =
                new System.Drawing.Pen(Color.Black, 0);

            Rectangle rect = e.Bounds;

            rect.Inflate(-1, -1);
            rect.Width  -= 1;
            rect.Height -= 1;

            e.Graphics.RenderingOrigin = new Point(0, 0);
            e.Graphics.FillRectangle(brush, rect);
            e.Graphics.DrawRectangle(pen, rect);

            pen.Dispose();
            brush.Dispose();
        }
Пример #3
0
		void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e)
		{
			e.DrawBackground();
			if (e.Index >= 0)
			{
				Rectangle rectangle = new Rectangle(4, e.Bounds.Top + 2, 30, e.Bounds.Height - 4);
				Color rectColor = (Color)Items[e.Index];
				e.Graphics.FillRectangle(new SolidBrush(rectColor), rectangle);
				e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rectangle);
				if (e.Index == 0)
				{
					e.Graphics.DrawString("Custom", e.Font, System.Drawing.Brushes.Black,
						new PointF(42, e.Bounds.Top + 2));
				}
				else
				{
					e.Graphics.DrawString(((Color)Items[e.Index]).Name, e.Font, System.Drawing.Brushes.Black,
						new PointF(42, e.Bounds.Top + 2));
				}
				if (!Enabled)
				{
					HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.LightGray, Color.FromArgb(10, Color.LightGray));
					rectangle.Inflate(1, 1);
					e.Graphics.FillRectangle(brush, rectangle);
					brush.Dispose();
				}
				e.DrawFocusRectangle();
			}
		}
        /*产生验证图片*/
        public void CreateImages(string code)
        {
            int fontsize = 20;

            int width = code.Length * fontsize;
            int height = fontsize + 8;

            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(bmp);
            HatchBrush b = new HatchBrush(HatchStyle.DiagonalCross, Color.LightGray, Color.WhiteSmoke);
            g.FillRectangle(b, 0, 0, width, height);

            Random random = new Random();
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
            new Rectangle(0, 0, bmp.Width, bmp.Height), Color.Black, Color.FromArgb(120, 120, 120), 20.0f, true);

            g.DrawString(code, new Font("Courier New", fontsize, FontStyle.Bold), brush, 2.0F, 1.0F);

            //画图片的前景噪音点
            for (int i = 0; i < 50; i++)
            {
                int x = random.Next(bmp.Width);
                int y = random.Next(bmp.Height);
                bmp.SetPixel(x, y, Color.Green);
            }

            bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
            b.Dispose();
            g.Dispose();
            bmp.Dispose();
        }
Пример #5
0
		private void HatchBrushes_Paint(object sender, PaintEventArgs e)
		{
			
			int y = 20;
			int x = 20;

            Font font = new Font("Tahoma", 8);
			// Enumerate over all the styles.
			foreach (HatchStyle brushStyle in System.Enum.GetValues(typeof(HatchStyle)))
			{
				HatchBrush myBrush = new HatchBrush(brushStyle, Color.Blue, Color.LightYellow);

				// Fill a rectangle with the brush.
				e.Graphics.FillRectangle(myBrush, x, y, 40, 20);

				// Display the brush name.
				e.Graphics.DrawString(brushStyle.ToString(), font,
					Brushes.Black, 50 + x, y + 5);

				y += 30;
				if ((y + 30) > this.ClientSize.Height)
				{
					y = 20;
					x += 180;
				}
                myBrush.Dispose();
			}
            font.Dispose();
		}
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
            {
                Graphics g = e.Graphics;
                {
                    HatchBrush hatchBrush = null;

                    Pen pen = null;

                    try
                    {
                        switch (FileDlgStartLocation)
                        {
                        case AddonWindowLocation.Right:
                            hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red);

                            pen = new Pen(hatchBrush, 5);

                            g.DrawLine(pen, 0, 0, 0, this.Height);
                            break;

                        case AddonWindowLocation.Bottom:
                            hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red);

                            pen = new Pen(hatchBrush, 5);

                            g.DrawLine(pen, 0, 0, this.Width, 0);
                            break;

                        case AddonWindowLocation.BottomRight:
                        default:
                            hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red);

                            pen = new Pen(hatchBrush, 5);

                            g.DrawLine(pen, 0, 0, 4, 4);
                            break;
                        }
                    }
                    catch (Exception exc)
                    {
                    }
                    finally
                    {
                        if (pen != null)
                        {
                            pen.Dispose();
                        }

                        if (hatchBrush != null)
                        {
                            hatchBrush.Dispose();
                        }
                    }
                }
            }

            base.OnPaint(e);
        }
		protected override void DrawSlider( PaintEventArgs e )
		{
			float		fSizeToDraw = m_SliderRectangle.Width * (Value - VisibleRangeMin) / (VisibleRangeMax - VisibleRangeMin);

			if ( m_ColorMin.A == 255 && m_ColorMax.A == 255 )
				e.Graphics.FillRectangle( m_BackgroundBrush, m_SliderRectangle.X + fSizeToDraw, m_SliderRectangle.Y, m_SliderRectangle.Width - fSizeToDraw, m_SliderRectangle.Height );
			else
			{	// Draw a nice checker box background
				System.Drawing.Drawing2D.HatchBrush	Checker = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.Gray, Color.DarkGray );

				e.Graphics.FillRectangle( Checker, m_SliderRectangle );

				Checker.Dispose();
			}

			// Draw a gradient box
			if ( fSizeToDraw < 1.0f )
				return;	// Crashes if empty!

			RectangleF	Rect = new RectangleF( m_SliderRectangle.X, m_SliderRectangle.Y, fSizeToDraw, m_SliderRectangle.Height );

			System.Drawing.Drawing2D.GraphicsPath		Path = new System.Drawing.Drawing2D.GraphicsPath();
														Path.AddRectangle( Rect );

			System.Drawing.Drawing2D.PathGradientBrush	Gradient = new System.Drawing.Drawing2D.PathGradientBrush( Path );
														Gradient.SurroundColors = new Color[] { m_ColorMin, m_ColorMax, m_ColorMax, m_ColorMin };
 														Gradient.CenterPoint = new PointF( 0.5f * (Rect.Left + Rect.Right), .5f * (Rect.Bottom + Rect.Top) );
 														Gradient.CenterColor = Color.FromArgb( (m_ColorMin.A + m_ColorMax.A) / 2, (m_ColorMin.R + m_ColorMax.R) / 2, (m_ColorMin.G + m_ColorMax.G) / 2, (m_ColorMin.B + m_ColorMax.B) / 2 );

			e.Graphics.FillRectangle( Gradient, Rect );

 			Gradient.Dispose();
 			Path.Dispose();
		}
        public override Bitmap Build(string text)
        {
            var random = new Random();
            var bitmap = new Bitmap
                (Width, Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            var rect = new Rectangle(0, 0, Width, Height);
            var hatchBrush = new HatchBrush(HatchStyle.SmallConfetti,
                Color.LightGray, Color.White);
            g.FillRectangle(hatchBrush, rect);
            SizeF size;
            float fontSize = rect.Height + 1;
            Font font;

            do
            {
                fontSize--;
                font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
                size = g.MeasureString(text, font);
            } while (size.Width > rect.Width);
            var format = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};
            var path = new GraphicsPath();
            //path.AddString(this.text, font.FontFamily, (int) font.Style,
            //    font.Size, rect, format);
            path.AddString(text, font.FontFamily, (int) font.Style, 75, rect, format);
            float v = 4F;
            PointF[] points =
            {
                new PointF(random.Next(rect.Width)/v, random.Next(
                    rect.Height)/v),
                new PointF(rect.Width - random.Next(rect.Width)/v,
                    random.Next(rect.Height)/v),
                new PointF(random.Next(rect.Width)/v,
                    rect.Height - random.Next(rect.Height)/v),
                new PointF(rect.Width - random.Next(rect.Width)/v,
                    rect.Height - random.Next(rect.Height)/v)
            };
            var matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
            hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue);
            g.FillPath(hatchBrush, path);
            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int) (rect.Width*rect.Height/30F); i++)
            {
                int x = random.Next(rect.Width);
                int y = random.Next(rect.Height);
                int w = random.Next(m/50);
                int h = random.Next(m/50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }
            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();
            return bitmap;
        }
Пример #9
0
        public void PaintPath(Graphics g, System.Drawing.Drawing2D.GraphicsPath path)
        {
            HatchBrush brush = new HatchBrush(style, color1, color2);
            g.FillPath(brush, path);
            brush.Dispose();

            if(numericUpDown1.Value != 0)
            {
                Pen pen = new Pen(colorBorder, (float)numericUpDown1.Value);
                g.DrawPath(pen, path);
                pen.Dispose();
            }
        }
Пример #10
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
            {
                Graphics gr = e.Graphics;
                {
                    HatchBrush hb = null;
                    Pen        p  = null;
                    try
                    {
                        switch (this.StartLocation)
                        {
                        case AddonWindowLocation.Right:
                            hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red);
                            p  = new Pen(hb, 5);
                            gr.DrawLine(p, 0, 0, 0, this.Height);
                            break;

                        case AddonWindowLocation.Bottom:
                            hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red);
                            p  = new Pen(hb, 5);
                            gr.DrawLine(p, 0, 0, this.Width, 0);
                            break;

                        case AddonWindowLocation.BottomRight:
                        default:
                            hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red);
                            p  = new Pen(hb, 5);
                            gr.DrawLine(p, 0, 0, 4, 4);
                            break;
                        }
                    }
                    finally
                    {
                        if (p != null)
                        {
                            p.Dispose();
                        }
                        if (hb != null)
                        {
                            hb.Dispose();
                        }
                    }
                }
            }
            base.OnPaint(e);
        }
Пример #11
0
		public override void DrawSelection(System.Drawing.Graphics g)
		{
			Color selColor = Color.Red;
			int border = 3;

			Rectangle r = BaseElement.GetUnsignedRectangle(
				new Rectangle(
					el.Location.X - border, el.Location.Y - border,
					el.Size.Width + (border * 2), el.Size.Height + (border * 2)));

			HatchBrush brush = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightGray, Color.Transparent);
			Pen p = new Pen(brush, border);
			g.DrawEllipse(p, r);

			p.Dispose();
			brush.Dispose();
		}
        protected override void OnPaint(PaintEventArgs paintEvent)
        {
            base.OnPaint(paintEvent);

            // Clear Control
            paintEvent.Graphics.Clear(BackColor);

            // Draw Borders
            paintEvent.Graphics.DrawRectangle(new Pen(_borderColor), new Rectangle(0, 0, Width - 1, Height - 1));

            // Draw Groupbox Header
            paintEvent.Graphics.FillRectangle(new SolidBrush(_headerColor), new Rectangle(0, 0, Width, 25));

            // Draw Groupbox Container
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.Percent80, Color.FromArgb(45, Color.FromArgb(39, 38, 38)), Color.Transparent);
            paintEvent.Graphics.FillRectangle(hatchBrush, new Rectangle(0, 0, Width, Height));

            // Draw Groupbox Title
            paintEvent.Graphics.DrawString(this.Text, _textFont, new SolidBrush(_textColor), new PointF(5, 5));

            // Dispose Of Brushes
            hatchBrush.Dispose();
        }
Пример #13
0
		protected override void OnDrawItem(DrawItemEventArgs e)
		{
			base.OnDrawItem(e);

			e.DrawBackground();

			HatchStyle style = FromString((string)this.Items[e.Index]);
			System.Drawing.Drawing2D.HatchBrush brush =
				new System.Drawing.Drawing2D.HatchBrush(style, Color.Black, e.BackColor);
			System.Drawing.Pen pen =
				new System.Drawing.Pen(Color.Black, 0);

			Rectangle rect = e.Bounds;
			rect.Inflate(-1, -1);
			rect.Width -= 1;
			rect.Height -= 1;

			e.Graphics.RenderingOrigin = new Point(0, 0);
			e.Graphics.FillRectangle(brush, rect);
			e.Graphics.DrawRectangle(pen, rect);

			pen.Dispose();
			brush.Dispose();
		}
Пример #14
0
    /// <summary>
    /// The generate image.
    /// </summary>
    private void GenerateImage()
    {
      var r = new Random();

      // Create a new 32-bit bitmap image.
      var bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);

      // Create a graphics object for drawing.
      Graphics g = Graphics.FromImage(bitmap);
      g.SmoothingMode = SmoothingMode.AntiAlias;
      var rect = new Rectangle(0, 0, this.width, this.height);

      var randomLineColor = this.random.Next(40) + 200;

      // Fill in the background.
      var hatchBrush = new HatchBrush(
        HatchStyle.SmallConfetti, Color.FromArgb(randomLineColor, randomLineColor, randomLineColor), Color.White);
      g.FillRectangle(hatchBrush, rect);

      // Set up the text font.
      SizeF size;
      float fontSize = rect.Height + 1;
      Font font;

      // Adjust the font size until the text fits within the image.
      do
      {
        fontSize--;
        font = new Font(this.familyName, fontSize, FontStyle.Bold);
        size = g.MeasureString(this.text, font);
      }
      while (size.Width > rect.Width);

      // Set up the text format.
      var format = new StringFormat();
      format.Alignment = StringAlignment.Center;
      format.LineAlignment = StringAlignment.Center;

      // Create a path using the text and warp it randomly.
      var path = new GraphicsPath();
      path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
      float v = 4F;
      PointF[] points = {
                          new PointF(r.Next(rect.Width) / v, r.Next(rect.Height) / v), 
                          new PointF(rect.Width - r.Next(rect.Width) / v, r.Next(rect.Height) / v), 
                          new PointF(r.Next(rect.Width) / v, rect.Height - r.Next(rect.Height) / v), 
                          new PointF(rect.Width - r.Next(rect.Width) / v, rect.Height - r.Next(rect.Height) / v)
                        };
      var matrix = new Matrix();
      matrix.Translate(0F, 0F);
      path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

      var randomColor = Color.FromArgb(
        this.random.Next(100) + 100, this.random.Next(100) + 100, this.random.Next(100) + 100);
      var randomBackground = Color.FromArgb(
        20 + this.random.Next(100), 20 + this.random.Next(100), 20 + this.random.Next(100));

      // Draw the text.
      hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, randomColor, randomBackground);
      g.FillPath(hatchBrush, path);

      // Add some random noise.
      int m = Math.Max(rect.Width, rect.Height);
      for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
      {
        int x = r.Next(rect.Width);
        int y = r.Next(rect.Height);
        int w = r.Next(m / (this.random.Next(1000) + 50));
        int h = r.Next(m / (this.random.Next(1000) + 50));

        g.FillEllipse(hatchBrush, x, y, w, h);
      }

      double noise = this.random.Next(35) + 35;

      int maxDim = Math.Max(rect.Width, rect.Height);
      var radius = (int)(maxDim * noise / 3000);
      var maxGran = (int)(rect.Width * rect.Height / (100 - (noise >= 90 ? 90 : noise)));
      for (int i = 0; i < maxGran; i++)
      {
        g.FillEllipse(
          hatchBrush, 
          this.random.Next(rect.Width), 
          this.random.Next(rect.Height), 
          this.random.Next(radius), 
          this.random.Next(radius));
      }

      double _lines = this.random.Next(25) + 15;

      if (_lines > 0)
      {
        int lines = ((int)_lines / 30) + 1;
        using (var pen = new Pen(hatchBrush, 1))
          for (int i = 0; i < lines; i++)
          {
            var pointsLine = new PointF[lines > 2 ? lines - 1 : 2];
            for (int j = 0; j < pointsLine.Length; j++)
            {
              pointsLine[j] = new PointF(this.random.Next(rect.Width), this.random.Next(rect.Height));
            }

            g.DrawCurve(pen, pointsLine, 1.75F);
          }
      }

      // Clean up.
      font.Dispose();
      hatchBrush.Dispose();

      g.Dispose();

      // Set the image.
      this.image = bitmap;
    }
Пример #15
0
		public Bitmap Type2(string text, int width, int height)
		{
			//Create instance of bitmap object
			Bitmap objBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

			//Create instance of graphics object
			Graphics objGraphics = Graphics.FromImage(objBitmap);
			objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
			Rectangle objRect = new Rectangle(0, 0, width, height);

			//Fill the background in a light gray pattern
			HatchBrush objHatchBrush = new HatchBrush(HatchStyle.DiagonalCross, Color.LightGray, Color.White);
			objGraphics.FillRectangle(objHatchBrush, objRect);

			//Determine the appropriate font size
			SizeF objSize;
			float flFontSize = objRect.Height + 1;
			Font objFont;
			do	//Decrease font size until text fits within the space
			{
				flFontSize--;
				objFont = new Font(System.Drawing.FontFamily.GenericSansSerif.Name, flFontSize, FontStyle.Bold);
				objSize = objGraphics.MeasureString(text, objFont);
			} while (objSize.Width > objRect.Width);

			//Format the text
			StringFormat objStringFormat = new StringFormat();
			objStringFormat.Alignment = StringAlignment.Center;
			objStringFormat.LineAlignment = StringAlignment.Center;

			//Create a path using the text and randomly warp it
			GraphicsPath objGraphicsPath = new GraphicsPath();
			objGraphicsPath.AddString(text, objFont.FontFamily, (int)objFont.Style, objFont.Size, objRect, objStringFormat);
			float flV = 4F;

			//Create a parallelogram for the text to draw into
			PointF[] arrPoints =
			{
				new PointF(HipRandom.Next(objRect.Width) / flV, HipRandom.Next(objRect.Height) / flV),
				new PointF(objRect.Width - HipRandom.Next(objRect.Width) / flV, HipRandom.Next(objRect.Height) / flV),
				new PointF(HipRandom.Next(objRect.Width) / flV, objRect.Height - HipRandom.Next(objRect.Height) / flV),
				new PointF(objRect.Width - HipRandom.Next(objRect.Width) / flV, objRect.Height - HipRandom.Next(objRect.Height) / flV)
			};

			//Create the warped parallelogram for the text
			Matrix objMatrix = new Matrix();
			objMatrix.Translate(0F, 0F);
			objGraphicsPath.Warp(arrPoints, objRect, objMatrix, WarpMode.Perspective, 0F);

			//Add the text to the shape
			objHatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.DarkGray, Color.Black);
			objGraphics.FillPath(objHatchBrush, objGraphicsPath);

			//Add some random noise
			int intMax = Math.Max(objRect.Width, objRect.Height);
			for (int i = 0; i < (int)(objRect.Width * objRect.Height / 30F); i++)
			{
				int x = HipRandom.Next(objRect.Width);
				int y = HipRandom.Next(objRect.Height);
				int w = HipRandom.Next(intMax / 15);
				int h = HipRandom.Next(intMax / 70);
				objGraphics.FillEllipse(objHatchBrush, x, y, w, h);
			}

			//Release memory
			objFont.Dispose();
			objHatchBrush.Dispose();
			objGraphics.Dispose();

			//Set the public property to the 
			return objBitmap;
		}
 private void AddBackgroundNoise(Graphics graphics, Rectangle rect)
 {
     HatchBrush brush = new HatchBrush(HatchStyle.SmallConfetti, BackgroundNoiseColor, BackgroundColor);
     graphics.FillRectangle(brush, rect);
     brush.Dispose();
 }
        private void AddForegroundNoise(Graphics graphics, Rectangle rect)
        {
            HatchBrush brush = new HatchBrush(HatchStyle.LargeConfetti, ForegroundNoiseColor, BackgroundNoiseColor);

            int max = Math.Max(rect.Width, rect.Height);
            for(int i = 0; i < ((rect.Width * rect.Height) / NoiseDivisor); i++)
            {
                int x = m_random.Next(rect.Left, rect.Left + rect.Width);
                int y = m_random.Next(rect.Top, rect.Top + rect.Width);
                int w = m_random.Next(max / 50);
                int h = m_random.Next(max / 50);

                graphics.FillEllipse(brush, x, y, w, h);
            }

            brush.Dispose();
        }
        /// <summary>
        /// Highlight a geographic object.
        /// </summary>
        /// @param record_number Array index of the record to be highlighted.
        /// @param c The color to use to highlight the record.
        private void Highlight(int record_number, Color c)
        {
            RenderThread drawThread;
            Pen tempPen = (Pen) _pen.Clone();
            tempPen.Color = c;

            if ( _ShapeType == ShapeType.Line )
            {
                tempPen.Width += 2;
                tempPen.StartCap = LineCap.RoundAnchor;
                tempPen.EndCap = LineCap.RoundAnchor;
            }

            HatchBrush tempBrush = new HatchBrush( HatchStyle.Percent70, c, Color.Transparent );

            drawThread = new RenderThread( _mapMetrics, _features,
                _ShapeType, record_number, record_number + 1, tempPen, tempBrush );

            drawThread.Start();

            tempPen.Dispose();
            tempBrush.Dispose();
        }
Пример #19
0
        private static void GenerateImage()
        {
            int width = 210, height = 70;
            string familyName = "Arial";
            string text = "";
            string temp = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
            for (int i = 0; i < 4; ++i) {
                text += temp[rand.Next(temp.Length)];
            }
            // Create a new 32-bit bitmap image.

            Bitmap bitmap = new Bitmap(
              width,
              height,
              PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.

            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, width, height);

            // Fill in the background.

            HatchBrush hatchBrush = new HatchBrush(
                HatchStyle.Shingle,
                //Color.LightGray,
                //Color.White);
                Color.FromArgb(rand.Next(224, 256), rand.Next(224, 256), rand.Next(224, 256)),
                Color.FromArgb(rand.Next(192, 224), rand.Next(192, 224), rand.Next(192, 224)));
            g.FillRectangle(hatchBrush, rect);

            // Set up the text font.

            float fontSize = rect.Height;
            Font font = new Font(familyName, fontSize, FontStyle.Bold);
            SizeF size = g.MeasureString(text, font);
            // Adjust the font size until the text fits within the image.

            do {
                fontSize--;
                font = new Font(
                  familyName,
                  fontSize,
                  FontStyle.Bold);
                size = g.MeasureString(text, font);
            } while (size.Width > rect.Width);

            // Set up the text format.

            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            // Create a path using the text and warp it randomly.
            GraphicsPath path = new GraphicsPath();
            path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, format);
            float v = 10;
            PointF[] points ={
                        new PointF(rand.Next(rect.Width)/v-20,rand.Next(rect.Height)/v),
                        new PointF(rect.Width - rand.Next(rect.Width)/v-20,rand.Next(rect.Height)/v),
                        new PointF(rand.Next(rect.Width)/v-20,rect.Height - rand.Next(rect.Height)/v),
                        new PointF(rect.Width - rand.Next(rect.Width)/v-20,rect.Height - rand.Next(rect.Height)/v)
                    };
            for (int i = 0; i < 1; ++i) {
                System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.Translate(0F, 0F);
                path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
            }
            // Draw the text.

            hatchBrush = new HatchBrush(
              HatchStyle.LargeConfetti,
                //Color.DarkGray,
                //Color.Black);
                Color.FromArgb(rand.Next(64, 128), rand.Next(64, 128), rand.Next(64, 128)),
                Color.FromArgb(rand.Next(0, 64), rand.Next(0, 64), rand.Next(0, 64)));
            g.FillPath(hatchBrush, path);

            // Add some random noise.

            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) {
                int x = rand.Next(rect.Width);
                int y = rand.Next(rect.Height);
                int w = rand.Next(m / 50);
                int h = rand.Next(m / 50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }

            // Clean up.

            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();

            for (int i = 0; i < 1; ++i)
                bitmap = wave(bitmap);

            // Set the image.
            bitmap.Save(Path.Combine(@"D:\Play Data\my_captcha", text + ".jpg"), ImageFormat.Jpeg);
        }
Пример #20
0
        public void GenerateImage()
        {
            //---- WITHOUT an image for the background ------

            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, this.width, this.height);

            // Fill in the background.
            //HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, ColorTranslator.FromHtml("#607f20"), ColorTranslator.FromHtml("#ffea00"));
            //HatchBrush hatchBrush = new HatchBrush(HatchStyle.Trellis, ColorTranslator.FromHtml("#ffffff"), ColorTranslator.FromHtml("#607f20"));
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.FromArgb(114,172,236), Color.FromArgb(161,214,255));
            //Color.FromArgb(76,136,198)    medium
            //Color.FromArgb(0,79,136)      dark
            //Color.FromArgb(114,172,236)   medium-light
            //Color.FromArgb(135,188,254)   light
            //Color.FromArgb(161,214,255)   really light
            g.FillRectangle(hatchBrush, rect);

            //---- WITH a background image ----------
            //string bgpath = HttpContext.Current.Server.MapPath("CaptchaBG.bmp");
            //Bitmap bitmap = new Bitmap(bgpath);
            //Graphics g = Graphics.FromImage(bitmap);
            //g.SmoothingMode = SmoothingMode.AntiAlias;
            //HatchBrush hatchBrush = null;
            //Rectangle rect = new Rectangle(0, 0, this.width, this.height);

            //-----------------------------------------

            // Set up the text font.
            SizeF size;
            float fontSize = this.height + 4;
            Font font;
            // Adjust the font size until the text fits within the image.
            do
            {
                fontSize--;
                font = new Font(this.familyName, fontSize, FontStyle.Bold);
                size = g.MeasureString(this.text, font);
            } while (size.Width > this.width);

            // Set up the text format.
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            // Create a path using the text and warp it randomly.
            GraphicsPath path = new GraphicsPath();
            path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
            float v = 4F;
            PointF[] points =
                {
                    new PointF(random.Next(this.width) / v, random.Next(this.height) / v),
                    new PointF(this.width - random.Next(this.width) / v, random.Next(this.height) / v),
                    new PointF(random.Next(this.width) / v, this.height - random.Next(this.height) / v),
                    new PointF(this.width - random.Next(this.width) / v, this.height - random.Next(this.height) / v)
                };
            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            // Draw the text.
            hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, ColorTranslator.FromHtml("#000000"), ColorTranslator.FromHtml("#000000"));
            //  white numbers
            //  hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, ColorTranslator.FromHtml("#ffffff"), ColorTranslator.FromHtml("#ffffff"));
            //  yellow numbers
            //hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, ColorTranslator.FromHtml("#ffea00"), ColorTranslator.FromHtml("#ffea00"));
            g.FillPath(hatchBrush, path);

            //// Add some random noise.
            int m = Math.Max(this.width, this.height);
            for (int i = 0; i < (int)(this.width * this.height / 30F); i++)
            {
                int x = random.Next(this.width);
                int y = random.Next(this.height);
                int w = random.Next(m / 50);
                int h = 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;
        }
        // ====================================================================
        // Creates the bitmap image.
        // ====================================================================
        private void GenerateImage()
        {
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, width, height);

            // Fill in the background.
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
            g.FillRectangle(hatchBrush, rect);

            // Set up the text font.
            SizeF size;
            float fontSize = rect.Height + 1;
            Font font;
            // Adjust the font size until the text fits within the image.
            do
            {
                fontSize--;
                font = new Font(familyName, fontSize, FontStyle.Bold);
                size = g.MeasureString(text, font);
            } while (size.Width > rect.Width);

            // Set up the text format.
            StringFormat format = new StringFormat
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            // Create a path using the text and warp it randomly.
            GraphicsPath path = new GraphicsPath();
            path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, format);
            float v = 4F;
            PointF[] points =
            {
                new PointF(random.Next(rect.Width) / v, random.Next(rect.Height) / v),
                new PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v),
                new PointF(random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v),
                new PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v)
            };
            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            // Draw the text.
            hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
            g.FillPath(hatchBrush, path);

            // Add some random noise.
            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
            {
                int x = random.Next(rect.Width);
                int y = random.Next(rect.Height);
                int w = random.Next(m / 50);
                int h = random.Next(m / 50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }

            // Clean up.
            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();

            // Set the image.
            image = bitmap;
        }
        /// <summary>
        /// Begin a tracking indicator in the specified control using the specified rectangle.
        /// </summary>
        ///	<param name="control">The control into which the tracking indicator will be drawn.</param>
        /// <param name="rectangle">Rectangle structure that represents the tracking indicator rectangle, relative to the upper-left corner of the control into which it will be drawn.</param>
        public void Begin(Control control, Rectangle rectangle)
        {
            //	Can't Begin twice.
            Debug.Assert(!valid, "Invalid nested Begin", "You must first call the End method of a VerticalTrackingIndicator before calling its Begin method again.");
            if (valid)
                End();

            //	Save away the control.  We need this so we can call ReleaseDC later on.
            this.control = control;

            //	Get a DC for the "visible region" the specified control.  Children are not clipped
            //	for this DC, which allows us to draw the tracking indicator over them.
            controlDC = GetDCEx(control.Handle, System.IntPtr.Zero, DCX_PARENTCLIP);

            //	Get a graphics object for the DC.
            controlGraphics = Graphics.FromHdc(controlDC);

            //	Instantiate the capture bitmap.
            captureBitmap = new Bitmap(rectangle.Width, rectangle.Height);

            //	Instantiate and paint the tracking indicator bitmap.
            trackingIndicatorBitmap = new Bitmap(rectangle.Width, rectangle.Height);
            Graphics trackingIndicatorBitmapGraphics = Graphics.FromImage(trackingIndicatorBitmap);
            HatchBrush hatchBrush = new HatchBrush(	HatchStyle.Percent50,
                                                    Color.FromArgb(128, Color.Black),
                                                    Color.FromArgb(128, Color.White));
            trackingIndicatorBitmapGraphics.FillRectangle(hatchBrush, new Rectangle(0, 0, rectangle.Width, rectangle.Height));
            hatchBrush.Dispose();
            trackingIndicatorBitmapGraphics.Dispose();

            //	Draw the new tracking indicator.
            DrawTrackingIndicator(rectangle.Location);

            //	Valid now.
            valid = true;
        }
Пример #23
0
		public static Bitmap GetCaptchaImage(Color fg, Color bg, Color n) {
			int topPadding = 2; // top and bottom padding in pixels
			int sidePadding = 3; // side padding in pixels

			SolidBrush textBrush = new SolidBrush(fg);
			Font font = new Font(FontFamily.GenericSansSerif, 32, FontStyle.Bold);

			string guid = SessionKeyValue;

			Bitmap bmpCaptcha = new Bitmap(500, 500);
			Graphics graphics = Graphics.FromImage(bmpCaptcha);
			SizeF textSize = graphics.MeasureString(guid, font);

			bmpCaptcha.Dispose();
			graphics.Dispose();

			int bitmapWidth = sidePadding * 2 + (int)textSize.Width;
			int bitmapHeight = topPadding * 2 + (int)textSize.Height;
			bmpCaptcha = new Bitmap(bitmapWidth, bitmapHeight);
			graphics = Graphics.FromImage(bmpCaptcha);

			Rectangle rect = new Rectangle(0, 0, bmpCaptcha.Width, bmpCaptcha.Height);

			HatchBrush hatch1 = new HatchBrush(HatchStyle.SmallGrid, n, bg);

			HatchBrush hatch2 = new HatchBrush(HatchStyle.DiagonalCross, bg, Color.Transparent);

			graphics.FillRectangle(hatch1, rect);
			graphics.DrawString(guid, font, textBrush, sidePadding, topPadding);
			graphics.FillRectangle(hatch2, rect);

			HttpContext.Current.Response.ContentType = "image/x-png";

			using (MemoryStream memStream = new MemoryStream()) {
				bmpCaptcha.Save(memStream, ImageFormat.Png);
			}

			textBrush.Dispose();
			font.Dispose();
			hatch1.Dispose();
			hatch2.Dispose();
			graphics.Dispose();

			return bmpCaptcha;
		}
Пример #24
0
        private void DrawColorTheme(ref Graphics g, Theme _Theme, Matrix mTransMatrix, RectangleF CurExt)
        {
            Legend _Legend;
            Shape _Shape;
            //Polygon : Polyline : Point
            int i;
            int j;
            GraphicsPath gpShp = new GraphicsPath();
            GraphicsPath gpSelShp = new GraphicsPath();
            StringFormat _StringFormat = new StringFormat();
            _StringFormat.Alignment = StringAlignment.Center;
            _StringFormat.LineAlignment = StringAlignment.Center;
            _StringFormat.FormatFlags = StringFormatFlags.NoClip;

            bool BaseLyrVisibility = false;
            //*** Set an array of brush based on current theme legend items
            Brush[] BrLegend = new Brush[_Theme.Legends.Count];
            for (i = 0; i <= _Theme.Legends.Count - 1; i++)
            {
                _Legend = _Theme.Legends[i];
                if (_Legend.FillStyle == FillStyle.Solid)
                {
                    BrLegend[i] = new SolidBrush(_Legend.Color);
                }
                else if (_Legend.FillStyle == FillStyle.Transparent)
                {
                    BrLegend[i] = new SolidBrush(Color.Transparent);
                }
                else
                {
                    BrLegend[i] = new HatchBrush((HatchStyle)_Legend.FillStyle, _Legend.Color, Color.Transparent);
                }
            }

            Pen PnTheme = new Pen(_Theme.BorderColor, _Theme.BorderWidth);
            Pen BorderHighlight = new Pen(_Theme.BorderColor, _Theme.BorderWidth + 0.7F);
            BorderHighlight.Alignment = PenAlignment.Inset;
            BorderHighlight.DashStyle = _Theme.BorderStyle;

            if (_Theme.BorderWidth == 0)
                PnTheme.Color = Color.Transparent;
            //??? Strange that setting Pen width = 0 gives effect of Pen width 1. So this workaround
            PnTheme.DashStyle = _Theme.BorderStyle;

            HatchBrush BrSelection = new HatchBrush(HatchStyle.Percent40, m_SelectionColor, Color.Transparent);
            Pen PnSelection = new Pen(m_SelectionColor);

            //*** If lyr exists in theme.Layervisibility collection
            foreach (Layer Lyr in Layers)
            {
                //Traverse Layers collection
                {
                    if (Lyr.Extent.IntersectsWith(CurExt) || CurExt.Contains(Lyr.Extent) || Lyr.Extent.Contains(CurExt))
                    {
                        // Render layer only if it lies within current map extent
                        if (_Theme.Type == ThemeType.Color)
                        {
                            if (_Theme.LayerVisibility[Lyr.ID] == null)
                                BaseLyrVisibility = false;
                            else
                                BaseLyrVisibility = (bool)_Theme.LayerVisibility[Lyr.ID];
                        }
                        else if (_Theme.Type == ThemeType.Hatch)
                        {
                            BaseLyrVisibility = Lyr.Visible;
                        }

                        Hashtable ht = Lyr.GetRecords(Lyr.LayerPath + "\\" + Lyr.ID);
                        IDictionaryEnumerator dicEnumerator = ht.GetEnumerator();
                        if (Lyr.LayerType == ShapeType.Polygon & BaseLyrVisibility == true)
                        {
                            while (dicEnumerator.MoveNext())
                            {
                                //Traverse Shapes
                                _Shape = (Shape)dicEnumerator.Value;
                                if (_Shape.Extent.IntersectsWith(CurExt))
                                {
                                    //Render shape only if it lies within current map extent
                                    gpShp.Reset();
                                    for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                    {
                                        gpShp.AddPolygon((PointF[])_Shape.Parts[j]);
                                    }
                                    gpShp.Transform(mTransMatrix);
                                    if (_Theme.AreaIndexes.ContainsKey(_Shape.AreaId))
                                    {
                                        if (_Theme.MultiLegend == true)
                                        {
                                            {
                                                switch (_Theme.MultiLegendCriteria)
                                                {
                                                    case "SRC":
                                                        if (_Theme.MultiLegendCol.ContainsKey(((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).Source))
                                                        {
                                                            //TODO Optimize SolidBrush
                                                            g.FillPath(new SolidBrush(((Legends)_Theme.MultiLegendCol[((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).Source])[(int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo].Color), gpShp);
                                                        }

                                                        break;
                                                    case "SGP":
                                                        if (_Theme.MultiLegendCol.ContainsKey(((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).Subgroup))
                                                        {
                                                            g.FillPath(new SolidBrush(((Legends)_Theme.MultiLegendCol[((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).Subgroup])[(int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo].Color), gpShp);
                                                        }

                                                        break;
                                                    default:
                                                        if (_Theme.MultiLegendCol.ContainsKey(((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).MDFldVal[_Theme.MultiLegendCriteria]))
                                                        {
                                                            g.FillPath(new SolidBrush(((Legends)_Theme.MultiLegendCol[((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).MDFldVal[_Theme.MultiLegendCriteria]])[(int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo].Color), gpShp);
                                                        }

                                                        break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            g.FillPath(BrLegend[(int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo], gpShp);
                                        }
                                    }

                                    else
                                    {
                                        g.FillPath(BrLegend[BrLegend.Length - 1], gpShp);
                                    }
                                    try
                                    {
                                        //- Draw Specified Area's polygon to hightlight with different border
                                        if (_Shape.AreaId == this.AreaIDToHighlight)
                                        {
                                            g.DrawPath(BorderHighlight, gpShp);
                                        }
                                        else
                                        {
                                            //- Draw Area polygon Path
                                            g.DrawPath(PnTheme, gpShp);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        //Console.Write(ex.Message) '??? AFRERI Eritria problem
                                    }

                                    //*** Draw Base layer selection
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                        g.FillPath(BrSelection, gpShp);

                                    //-Exist Drawing Function
                                    if (_Shape.AreaId == this.AreaIDToHighlight)
                                    {
                                        break;
                                    }
                                }
                            }
                            //Traverse Shapes
                        }
                        else if (((Lyr.LayerType == ShapeType.PolygonFeature & BaseLyrVisibility == true) | ((Lyr.LayerType == ShapeType.PolygonCustom | Lyr.LayerType == ShapeType.PolygonBuffer) & Lyr.Visible == true)) & _Theme.Type == ThemeType.Color)
                        {
                            Pen PnLayer = new Pen(Lyr.BorderColor, Lyr.BorderSize);
                            if (Lyr.BorderSize == 0)
                                PnLayer.Color = Color.Transparent;
                            //??? Strange that setting Pen width = 0 gives effect of Pen width 1. So this workaround
                            PnLayer.DashStyle = Lyr.BorderStyle;
                            Brush BrLayer;
                            if (Lyr.FillStyle == FillStyle.Solid)
                            {
                                BrLayer = new SolidBrush(Lyr.FillColor);
                            }
                            else if (Lyr.FillStyle == FillStyle.Transparent)
                            {
                                BrLayer = new SolidBrush(Color.Transparent);
                            }
                            else
                            {
                                BrLayer = new HatchBrush((HatchStyle)Lyr.FillStyle, Lyr.FillColor, Color.Transparent);
                            }
                            gpShp.Reset();
                            gpShp.FillMode = FillMode.Winding;
                            gpSelShp.Reset();
                            gpSelShp.FillMode = FillMode.Winding;
                            while (dicEnumerator.MoveNext())
                            {
                                _Shape = (Shape)dicEnumerator.Value;
                                if (_Shape.Extent.IntersectsWith(CurExt))
                                {
                                    for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                    {
                                        try
                                        {
                                            gpShp.AddPolygon((PointF[])_Shape.Parts[j]);
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                        if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                            gpSelShp.AddPolygon((PointF[])_Shape.Parts[j]);
                                    }
                                }
                            }
                            gpShp.Transform(mTransMatrix);
                            g.FillPath(BrLayer, gpShp);
                            try
                            {
                                g.DrawPath(PnLayer, gpShp);
                            }
                            catch (Exception ex)
                            {
                                Console.Write(ex.Message);
                                //??? AFRERI Eritria problem
                            }
                            if (Lyr.SelectedArea.Count > 0)
                            {
                                gpSelShp.Transform(mTransMatrix);
                                g.FillPath(BrSelection, gpSelShp);
                            }
                            BrLayer.Dispose();
                            PnLayer.Dispose();
                        }
                        else if (Lyr.LayerType == ShapeType.PolyLine & BaseLyrVisibility == true & _Theme.Type == ThemeType.Color)
                        {
                            Pen PnLegend = new Pen(Lyr.BorderColor, Lyr.BorderSize);
                            PnLegend.DashStyle = Lyr.BorderStyle;
                            while (dicEnumerator.MoveNext())
                            {
                                //*** Traverse Shapes
                                _Shape = (Shape)dicEnumerator.Value;
                                gpShp.Reset();
                                for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                {
                                    gpShp.StartFigure();
                                    gpShp.AddLines((PointF[])_Shape.Parts[j]);
                                }
                                gpShp.Transform(mTransMatrix);
                                PnLegend.Color = _Theme.Legends[(int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo].Color;
                                g.DrawPath(PnLegend, gpShp);
                            }
                            PnLegend.Dispose();
                        }
                        else if (((Lyr.LayerType == ShapeType.PolyLineFeature & BaseLyrVisibility == true) | (Lyr.LayerType == ShapeType.PolyLineCustom & Lyr.Visible == true)) & _Theme.Type == ThemeType.Color)
                        {
                            gpShp.Reset();
                            while (dicEnumerator.MoveNext())
                            {
                                //*** Traverse Shapes
                                _Shape = (Shape)dicEnumerator.Value;
                                for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                {
                                    gpShp.StartFigure();
                                    gpShp.AddLines((PointF[])_Shape.Parts[j]);
                                }
                            }
                            Pen PnLayer = new Pen(Lyr.BorderColor, Lyr.BorderSize);
                            PnLayer.DashStyle = Lyr.BorderStyle;
                            gpShp.Transform(mTransMatrix);
                            g.DrawPath(PnLayer, gpShp);
                            PnLayer.Dispose();
                        }
                        else if (Lyr.LayerType == ShapeType.Point & BaseLyrVisibility == true)
                        {
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            {
                                PointF[] Pt = new PointF[1];
                                int LegendItemIndex;
                                int[] MarkerSize = new int[_Theme.Legends.Count];
                                //PtSize based on Legend item
                                char[] MarkerChar = new char[_Theme.Legends.Count];
                                Font[] MarkerFont = new Font[_Theme.Legends.Count];
                                Pen PnCross = (Pen)PnTheme.Clone();
                                for (i = 0; i <= _Theme.Legends.Count - 1; i++)
                                {
                                    _Legend = _Theme.Legends[i];
                                    MarkerSize[i] = _Legend.MarkerSize;
                                    MarkerChar[i] = _Legend.MarkerChar;
                                    MarkerFont[i] = _Legend.MarkerFont;
                                    if (_Legend.MarkerType == MarkerStyle.Cross)
                                        PnCross.Color = _Legend.Color;
                                }
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    //*** BugFix 04 July 2006 Base point layer missing data rendered with 1st legend information
                                    if (_Theme.AreaIndexes.ContainsKey(_Shape.AreaId))
                                    {
                                        LegendItemIndex = (int)((AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]).RenderingInfo;
                                    }
                                    else
                                    {
                                        LegendItemIndex = _Theme.Legends.Count - 1;
                                    }
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    switch (_Theme.Legends[LegendItemIndex].MarkerType)
                                    {
                                        case MarkerStyle.Circle:
                                            g.FillEllipse(BrLegend[LegendItemIndex], (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);
                                            g.DrawEllipse(PnTheme, (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);
                                            if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                                g.FillEllipse(BrSelection, (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);

                                            break;
                                        case MarkerStyle.Square:
                                            g.FillRectangle(BrLegend[LegendItemIndex], (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);
                                            g.DrawRectangle(PnTheme, (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);
                                            if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                                g.FillRectangle(BrSelection, (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2, MarkerSize[LegendItemIndex], MarkerSize[LegendItemIndex]);

                                            break;
                                        case MarkerStyle.Triangle:
                                            //*** 1.Equilateral triangle with altitude = MarkerSize(LegendItemIndex) 2.Equilateral triangle with sides = MarkerSize(LegendItemIndex)
                                            PointF[] Vertex = new PointF[3];
                                            int PtSize;
                                            PtSize = (int)(Math.Sqrt(3) / 4 * MarkerSize[LegendItemIndex]);
                                            Vertex[0] = new PointF(Pt[0].X - PtSize, Pt[0].Y + PtSize);
                                            //altitude = PtSize 'Vertex(0) = New PointF(pt(0).X - PtSize / 2, pt(0).Y + PtSize / 2) 'side = PtSize
                                            Vertex[1] = new PointF(Pt[0].X + PtSize, Pt[0].Y + PtSize);
                                            //altitude = PtSize 'Vertex(1) = New PointF(pt(0).X + PtSize / 2, pt(0).Y + PtSize / 2) 'side = PtSize
                                            Vertex[2] = new PointF(Pt[0].X, Pt[0].Y - PtSize);
                                            g.FillPolygon(BrLegend[LegendItemIndex], Vertex);
                                            g.DrawPolygon(PnTheme, Vertex);
                                            if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                                g.FillPolygon(BrSelection, Vertex);

                                            Vertex = null;
                                            break;
                                        case MarkerStyle.Cross:
                                            g.DrawLine(PnCross, (int)Pt[0].X - MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y, (int)Pt[0].X + MarkerSize[LegendItemIndex] / 2, (int)Pt[0].Y);
                                            g.DrawLine(PnCross, (int)Pt[0].X, (int)Pt[0].Y + MarkerSize[LegendItemIndex] / 2, (int)Pt[0].X, (int)Pt[0].Y - MarkerSize[LegendItemIndex] / 2);
                                            break;
                                        case MarkerStyle.Custom:
                                            g.DrawString(MarkerChar[LegendItemIndex].ToString(), MarkerFont[LegendItemIndex], BrLegend[LegendItemIndex], Pt[0].X, Pt[0].Y, _StringFormat);
                                            break;
                                    }
                                }
                                for (i = 0; i <= MarkerFont.Length - 1; i++)
                                {
                                    MarkerFont[i].Dispose();
                                }
                                Pt = null;
                                PnCross.Dispose();
                            }
                            g.SmoothingMode = SmoothingMode.None;
                        }
                        else if (((Lyr.LayerType == ShapeType.PointFeature & BaseLyrVisibility == true) | (Lyr.LayerType == ShapeType.PointCustom & Lyr.Visible == true)) & _Theme.Type == ThemeType.Color)
                        {
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            Pen PnLayer = new Pen(Lyr.FillColor, 0.01F);
                            Brush BrLayer = new SolidBrush(Lyr.FillColor);
                            PointF[] Pt = new PointF[1];
                            int PtSize = Lyr.MarkerSize;
                            // CInt((_Layer.MarkerSize * m_FullExtent.Width) / (8 * m_CurrentExtent.Width))
                            gpShp.Reset();
                            gpSelShp.Reset();
                            if (Lyr.MarkerStyle == MarkerStyle.Circle)
                            {
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                    {
                                        gpSelShp.AddEllipse((int)Pt[0].X - PtSize / 2, (int)Pt[0].Y - PtSize / 2, PtSize, PtSize);
                                    }
                                    else
                                    {
                                        gpShp.AddEllipse((int)Pt[0].X - PtSize / 2, (int)Pt[0].Y - PtSize / 2, PtSize, PtSize);
                                    }
                                }
                            }
                            else if (Lyr.MarkerStyle == MarkerStyle.Square)
                            {
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                    {
                                        gpSelShp.AddRectangle(new RectangleF(Pt[0].X - PtSize / 2, Pt[0].Y - PtSize / 2, PtSize, PtSize));
                                    }
                                    else
                                    {
                                        gpShp.AddRectangle(new RectangleF(Pt[0].X - PtSize / 2, Pt[0].Y - PtSize / 2, PtSize, PtSize));
                                    }
                                }
                            }
                            else if (Lyr.MarkerStyle == MarkerStyle.Triangle)
                            {
                                //*** 1.Equilateral triangle with altitude = PtSize 2.Equilateral triangle with sides = PtSize
                                PointF[] Vertex = new PointF[3];
                                PtSize = (int)(Math.Sqrt(3) / 4 * PtSize);
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    Vertex[0] = new PointF(Pt[0].X - PtSize, Pt[0].Y + PtSize);
                                    //altitude = PtSize 'Vertex(0) = New PointF(pt(0).X - PtSize / 2, pt(0).Y + PtSize / 2) 'side = PtSize
                                    Vertex[1] = new PointF(Pt[0].X + PtSize, Pt[0].Y + PtSize);
                                    //altitude = PtSize 'Vertex(1) = New PointF(pt(0).X + PtSize / 2, pt(0).Y + PtSize / 2) 'side = PtSize
                                    Vertex[2] = new PointF(Pt[0].X, Pt[0].Y - PtSize);
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                    {
                                        gpSelShp.AddPolygon(Vertex);
                                    }
                                    else
                                    {
                                        gpShp.AddPolygon(Vertex);
                                    }
                                }
                                Vertex = null;
                            }
                            else if (Lyr.MarkerStyle == MarkerStyle.Cross)
                            {
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                    {
                                        gpSelShp.AddLine(new PointF(Pt[0].X - PtSize / 2, Pt[0].Y), new PointF(Pt[0].X + PtSize / 2, Pt[0].Y));
                                        gpSelShp.CloseFigure();
                                        gpSelShp.AddLine(new PointF(Pt[0].X, Pt[0].Y + PtSize / 2), new PointF(Pt[0].X, Pt[0].Y - PtSize / 2));
                                        gpSelShp.CloseFigure();
                                    }
                                    else
                                    {
                                        gpShp.AddLine(new PointF(Pt[0].X - PtSize / 2, Pt[0].Y), new PointF(Pt[0].X + PtSize / 2, Pt[0].Y));
                                        gpShp.CloseFigure();
                                        gpShp.AddLine(new PointF(Pt[0].X, Pt[0].Y + PtSize / 2), new PointF(Pt[0].X, Pt[0].Y - PtSize / 2));
                                        gpShp.CloseFigure();
                                    }
                                }
                            }
                            else if (Lyr.MarkerStyle == MarkerStyle.Custom)
                            {
                                Font _MFnt = new Font(Lyr.MarkerFont.FontFamily, PtSize);
                                while (dicEnumerator.MoveNext())
                                {
                                    //*** Traverse Shapes
                                    _Shape = (Shape)dicEnumerator.Value;
                                    Pt[0] = (PointF)_Shape.Parts[0];
                                    mTransMatrix.TransformPoints(Pt);
                                    if (Lyr.SelectedArea.Contains(_Shape.AreaId))
                                    {
                                        g.DrawString(Lyr.MarkerChar.ToString(), _MFnt, BrSelection, Pt[0].X, Pt[0].Y, _StringFormat);
                                    }
                                    else
                                    {
                                        g.DrawString(Lyr.MarkerChar.ToString(), _MFnt, BrLayer, Pt[0].X, Pt[0].Y, _StringFormat);
                                    }
                                }
                                _MFnt.Dispose();
                            }
                            g.FillPath(BrLayer, gpShp);
                            g.DrawPath(PnLayer, gpShp);
                            g.FillPath(BrSelection, gpSelShp);
                            g.DrawPath(PnSelection, gpSelShp);
                            Pt = null;
                            PnLayer.Dispose();
                            BrLayer.Dispose();
                            g.SmoothingMode = SmoothingMode.None;
                        }
                        ht = null;
                    }
                }
                //Lyr = null;
            }
            //Traverse Layers collection

            _Shape = null;
            for (i = 0; i <= BrLegend.Length - 1; i++)
            {
                BrLegend[i].Dispose();
            }
            PnTheme.Dispose();
            BorderHighlight.Dispose();
            BrSelection.Dispose();
            PnSelection.Dispose();
            _StringFormat.Dispose();
            gpSelShp.Dispose();
            gpShp.Dispose();
        }
Пример #25
0
        private string GenerateImage()
        {
            Image = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(Image);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle r = new Rectangle(0, 0, Width, Height);
            HatchBrush hbr = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
            g.FillRectangle(hbr, r);
            float fSize = r.Height + 1;
            Font f;
            SizeF size;
            do
            {
                fSize--;
                f = new Font(familyName, fSize, FontStyle.Bold);
                size = g.MeasureString(Text, f);
            } while (size.Width > r.Width);

            StringFormat format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
            GraphicsPath path = new GraphicsPath();
            path.AddString(Text, f.FontFamily, (int)f.Style, f.Size, r, format);
            float v = 4F;
            PointF[] points =
            {
                new PointF(this.random.Next(r.Width) / v, this.random.Next(r.Height) / v),
                new PointF(r.Width - this.random.Next(r.Width) / v, this.random.Next(r.Height) / v),
                new PointF(this.random.Next(r.Width) / v, r.Height - this.random.Next(r.Height) / v),
                new PointF(r.Width - this.random.Next(r.Width) / v,r.Height -
                this.random.Next(r.Height) / v)
            };

            Matrix mx = new Matrix();
            mx.Translate(0F, 0F);
            path.Warp(points, r, mx, WarpMode.Perspective, 0F);
            hbr = new HatchBrush(HatchStyle.LargeConfetti, Color.DarkGray, Color.Gray);
            g.FillPath(hbr, path);

            int m = Math.Max(r.Width, r.Height);
            for (int i = 0; i < (int)(r.Width * r.Height / 30F); i++)
            {
                int x = this.random.Next(r.Width);
                int y = this.random.Next(r.Height);
                int w = this.random.Next(m / 50);
                int h = this.random.Next(m / 50);
                g.FillEllipse(hbr, x, y, w, h);
            }

            f.Dispose();
            hbr.Dispose();
            g.Dispose();

            MemoryStream ms = new MemoryStream();
            Image.Save(ms, ImageFormat.Png);
            return "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
        }
Пример #26
0
        public void Draw()
        {

            // Creates a 32bits bitmap
            Bitmap bitmap = new Bitmap(
                width,
                height,
                PixelFormat.Format32bppArgb);

            // A Graphic object in which to draw
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            // A rectangle to fill the image
            Rectangle rect = new Rectangle(0, 0, width, height);
            HatchBrush hatchBrush = new HatchBrush(
                HatchStyle.SmallConfetti,
                Color.LightGray,
                Color.White);
            g.FillRectangle(hatchBrush, rect);

            // Prepares the font
            SizeF textSize;
            float fontSize = rect.Height + 1;
            Font font;

            // Ajusts the size of the font
            do
            {
                fontSize--;
                font = new Font(
                    "Arial",
                    fontSize,
                    FontStyle.Bold);
                textSize = g.MeasureString(Text, font);
            } while (textSize.Width > rect.Width);

            // Text formating
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            // Random transform
            GraphicsPath path = new GraphicsPath();
            path.AddString(
                Text,
                font.FontFamily,
                (int)font.Style,
                font.Size,
                rect,
                format);
            float v = 4F;
            PointF[] points = new PointF[] {
                new PointF(
                    random.Next(rect.Width) / v,
                    random.Next(rect.Height) / v),
                new PointF(
                    rect.Width - random.Next(rect.Width) / v,
                    random.Next(rect.Height) / v),
                new PointF(
                    random.Next(rect.Width) / v,
                    rect.Height - random.Next(rect.Height) / v),
                new PointF(
                    rect.Width - random.Next(rect.Width) / v,
                    rect.Height - random.Next(rect.Height) / v)
            };
            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            // Draws text
            hatchBrush = new HatchBrush(
                HatchStyle.LargeConfetti,
                Color.LightGray,
                Color.DarkGray);
            g.FillPath(hatchBrush, path);
            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
            {
                int x = random.Next(rect.Width);
                int y = random.Next(rect.Height);
                int w = random.Next(m / 50);
                int h = random.Next(m / 50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }

            // Adds random lines
            Color[] colors = new Color[] { 
                Color.DarkGray, Color.Cyan, Color.Violet, Color.LightGreen, Color.Gold, Color.Gray, Color.HotPink, Color.LightPink };
            for (int i = 0; i < colors.Length; i++)
            {
                hatchBrush = new HatchBrush(
                HatchStyle.LargeConfetti,
                Color.LightGray,
                colors[i]);
                Pen pen = new Pen(hatchBrush);
                g.DrawLine(pen, new Point(random.Next(0, rect.Width), random.Next(0, rect.Width)), new Point(random.Next(0, rect.Height), random.Next(0, rect.Height)));
            }

            // Resources cleanup
            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();

            // Sets the image
            Image = bitmap;
        }
        /// <summary>
        /// Custom draw of items in dropdown control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDrawItem( object sender, DrawItemEventArgs e )
        {
            Graphics g = e.Graphics;
              Rectangle rc = e.Bounds;

              Rectangle rcPreView = new Rectangle( rc.X + 2, rc.Y + 2, 16, rc.Height - 4 );
              Rectangle rcText = new Rectangle( rcPreView.Right + 2, rc.Y,
            rc.Width - rcPreView.Width - 4, rc.Height );

              string text = clb.Items[ e.Index ].ToString();

              HatchStyle style = (HatchStyle)Enum.Parse( typeof( HatchStyle ), text, true );
              HatchBrush brush = new HatchBrush( style, e.ForeColor, e.BackColor );

              // draw background
              g.FillRectangle( new SolidBrush( e.BackColor ), rc );

              // draw preview
              g.FillRectangle( brush, rcPreView );
              g.DrawRectangle( Pens.Black, rcPreView.X, rcPreView.Y,
            rcPreView.Width - 1, rcPreView.Height - 1  );

              // draw string
              StringFormat format = new StringFormat( StringFormatFlags.LineLimit );
              format.Trimming = StringTrimming.EllipsisCharacter;
              format.LineAlignment = StringAlignment.Near;
              format.Alignment = StringAlignment.Near;

              g.DrawString( text, e.Font, new SolidBrush( e.ForeColor ), rcText, format );

              brush.Dispose();
        }
Пример #28
0
        private void DrawPort(Graphics gfx, HexEdge edge, Port port)
        {
            var linePoints = HexEdgeToAbsolutePoints(edge);
            if (linePoints != null)
            {
                Color c = port.Resource == ResourceTypes.None ? Color.Black : ResourceColorMap[port.Resource];
                Brush hb = new HatchBrush(HatchStyle.Wave, c, BoardColors.Water);
                Pen p = new Pen(c, 2f);
                Pen bp = new Pen(Color.Black, 1f);

                var box = linePoints.GetBoundingBox();
                gfx.DrawEllipse(bp, box.OffsetSize(2, 2));
                gfx.DrawEllipse(p, box);
                gfx.FillEllipse(hb, box);

                bp.Dispose();
                hb.Dispose();
                p.Dispose();
            }
        }
        private void GenerateImage()
        {
            Bitmap bitmap = new Bitmap
              (this.width, this.height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, this.width, this.height);
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti,
                Color.LightGray, Color.White);
            g.FillRectangle(hatchBrush, rect);
            SizeF size;
            float fontSize = rect.Height + 1;
            Font font;

            do
            {
                fontSize--;
                font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
                size = g.MeasureString(this.text, font);
            } while (size.Width > rect.Width);
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            GraphicsPath path = new 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;
            PointF[] points =
          {
                new PointF(this.random.Next(rect.Width) / v, this.random.Next(
                   rect.Height) / v),
                new PointF(rect.Width - this.random.Next(rect.Width) / v, 
                    this.random.Next(rect.Height) / v),
                new PointF(this.random.Next(rect.Width) / v, 
                    rect.Height - this.random.Next(rect.Height) / v),
                new PointF(rect.Width - this.random.Next(rect.Width) / v,
                    rect.Height - this.random.Next(rect.Height) / v)
          };
            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
            hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue);
            g.FillPath(hatchBrush, path);
            int m = 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;
        }
Пример #30
0
        private void DrawBaseLayer(ref Graphics g, Matrix mTransMatrix, RectangleF CurExt)
        {
            Shape _Shape;
            //Dim PnLayer As New Pen(Color.LightGray)
            HatchBrush BrSelection = new HatchBrush(HatchStyle.Percent40, m_SelectionColor, Color.Transparent);
            Pen PnSelection = new Pen(m_SelectionColor);

            GraphicsPath gpShp = new GraphicsPath();
            GraphicsPath gpSelShp = new GraphicsPath();
            StringFormat _StringFormat = new StringFormat();
            _StringFormat.Alignment = StringAlignment.Center;
            _StringFormat.LineAlignment = StringAlignment.Center;
            _StringFormat.FormatFlags = StringFormatFlags.NoClip;

            int j;
            foreach (Layer _Layer in Layers)
            {
                //Traverse Layers collection
                {
                    if (_Layer.Extent.IntersectsWith(CurExt) & _Layer.Visible == true)
                    {
                        // Render layer only if it lies within current map extent

                        Hashtable ht = _Layer.GetRecords(_Layer.LayerPath + "\\" + _Layer.ID);
                        IDictionaryEnumerator dicEnumerator = ht.GetEnumerator();
                        switch (_Layer.LayerType)
                        {
                            case ShapeType.Polygon:
                            case ShapeType.PolygonFeature:
                            case ShapeType.PolygonCustom:
                            case ShapeType.PolygonBuffer:
                                Pen PnLayer = new Pen(_Layer.BorderColor, _Layer.BorderSize);
                                if (_Layer.BorderSize == 0)
                                    PnLayer.Color = Color.Transparent;

                                //??? Strange that setting Pen width = 0 gives effect of Pen width 1. So this workaround
                                PnLayer.DashStyle = _Layer.BorderStyle;

                                Brush BrLayer;
                                if (_Layer.FillStyle == FillStyle.Solid)
                                {
                                    BrLayer = new SolidBrush(_Layer.FillColor);
                                }
                                else if (_Layer.FillStyle == FillStyle.Transparent)
                                {
                                    BrLayer = new SolidBrush(Color.Transparent);
                                }
                                else
                                {
                                    BrLayer = new HatchBrush((HatchStyle)_Layer.FillStyle, _Layer.FillColor, Color.Transparent);
                                }

                                //While dicEnumerator.MoveNext()
                                // _Shape = dicEnumerator.Value
                                // If _Shape.Extent.IntersectsWith(CurExt) Then
                                // gpShp.Reset()
                                // For j = 0 To _Shape.Parts.Count - 1
                                // gpShp.AddPolygon(_Shape.Parts(j))
                                // Next
                                // gpShp.Transform(mTransMatrix)
                                // If _Layer.LayerType <> ShapeType.Polygon Then g.FillPath(BrLayer, gpShp)
                                // g.DrawPath(PnLayer, gpShp)
                                // If .SelectedArea.Contains(_Shape.AreaId) Then g.FillPath(BrSelection, gpShp)
                                // End If
                                //End While

                                gpShp.Reset();
                                gpShp.FillMode = FillMode.Winding;
                                gpSelShp.Reset();
                                gpSelShp.FillMode = FillMode.Winding;
                                while (dicEnumerator.MoveNext())
                                {
                                    _Shape = (Shape)dicEnumerator.Value;
                                    if (_Shape.Extent.IntersectsWith(CurExt))
                                    {
                                        for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                        {
                                            gpShp.AddPolygon((PointF[])_Shape.Parts[j]);
                                            if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                                gpSelShp.AddPolygon((PointF[])_Shape.Parts[j]);
                                        }
                                    }
                                }

                                gpShp.Transform(mTransMatrix);

                                if (_Layer.LayerType != ShapeType.Polygon)
                                {
                                    g.FillPath(BrLayer, gpShp);
                                }

                                try
                                {
                                    g.DrawPath(PnLayer, gpShp);
                                }
                                catch (Exception ex)
                                {
                                    Console.Write(ex.Message);
                                    //??? AFRERI Eritria problem
                                }

                                if (_Layer.SelectedArea.Count > 0)
                                {
                                    gpSelShp.Transform(mTransMatrix);
                                    g.FillPath(BrSelection, gpSelShp);
                                }

                                BrLayer.Dispose();
                                PnLayer.Dispose();
                                break;

                            case ShapeType.PolyLine:
                            case ShapeType.PolyLineFeature:
                            case ShapeType.PolyLineCustom:
                                gpShp.Reset();
                                while (dicEnumerator.MoveNext())
                                {
                                    _Shape = (Shape)dicEnumerator.Value;
                                    for (j = 0; j <= _Shape.Parts.Count - 1; j++)
                                    {
                                        gpShp.StartFigure();
                                        gpShp.AddLines((PointF[])_Shape.Parts[j]);
                                    }
                                }
                                PnLayer = null;
                                PnLayer = new Pen(_Layer.BorderColor, _Layer.BorderSize);
                                PnLayer.DashStyle = _Layer.BorderStyle;
                                gpShp.Transform(mTransMatrix);
                                g.DrawPath(PnLayer, gpShp);
                                PnLayer.Dispose();
                                break;

                            case ShapeType.Point:
                            case ShapeType.PointFeature:
                            case ShapeType.PointCustom:
                                g.SmoothingMode = SmoothingMode.AntiAlias;
                                PnLayer = new Pen(_Layer.FillColor, 0.01F);
                                BrLayer = new SolidBrush(_Layer.FillColor);
                                PointF[] Pt = new PointF[1];
                                int PtSize = _Layer.MarkerSize;
                                gpShp.Reset();
                                gpSelShp.Reset();
                                if (_Layer.MarkerStyle == MarkerStyle.Circle)
                                {
                                    while (dicEnumerator.MoveNext())
                                    {
                                        _Shape = (Shape)dicEnumerator.Value;
                                        Pt[0] = (PointF)_Shape.Parts[0];
                                        mTransMatrix.TransformPoints(Pt);
                                        if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                        {
                                            gpSelShp.AddEllipse((int)Pt[0].X - PtSize / 2, (int)Pt[0].Y - PtSize / 2, PtSize, PtSize);
                                        }
                                        else
                                        {
                                            gpShp.AddEllipse((int)Pt[0].X - PtSize / 2, (int)Pt[0].Y - PtSize / 2, PtSize, PtSize);
                                        }
                                    }
                                }
                                else if (_Layer.MarkerStyle == MarkerStyle.Square)
                                {
                                    while (dicEnumerator.MoveNext())
                                    {
                                        _Shape = (Shape)dicEnumerator.Value;
                                        Pt[0] = (PointF)_Shape.Parts[0];
                                        mTransMatrix.TransformPoints(Pt);
                                        if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                        {
                                            gpSelShp.AddRectangle(new RectangleF(Pt[0].X - PtSize / 2, Pt[0].Y - PtSize / 2, PtSize, PtSize));
                                        }
                                        else
                                        {
                                            gpShp.AddRectangle(new RectangleF(Pt[0].X - PtSize / 2, Pt[0].Y - PtSize / 2, PtSize, PtSize));
                                        }
                                    }
                                }
                                else if (_Layer.MarkerStyle == MarkerStyle.Triangle)
                                {
                                    //*** 1.Equilateral triangle with altitude = PtSize 2.Equilateral triangle with sides = PtSize
                                    PointF[] Vertex = new PointF[3];
                                    PtSize = (int)(Math.Sqrt(3) / 4 * PtSize);
                                    while (dicEnumerator.MoveNext())
                                    {
                                        _Shape = (Shape)dicEnumerator.Value;
                                        Pt[0] = (PointF)_Shape.Parts[0];
                                        mTransMatrix.TransformPoints(Pt);
                                        Vertex[0] = new PointF(Pt[0].X - PtSize, Pt[0].Y + PtSize);
                                        Vertex[1] = new PointF(Pt[0].X + PtSize, Pt[0].Y + PtSize);
                                        Vertex[2] = new PointF(Pt[0].X, Pt[0].Y - PtSize);
                                        if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                        {
                                            gpSelShp.AddPolygon(Vertex);
                                        }
                                        else
                                        {
                                            gpShp.AddPolygon(Vertex);
                                        }
                                    }
                                    Vertex = null;
                                }
                                else if (_Layer.MarkerStyle == MarkerStyle.Cross)
                                {
                                    while (dicEnumerator.MoveNext())
                                    {
                                        //*** Traverse Shapes
                                        _Shape = (Shape)dicEnumerator.Value;
                                        Pt[0] = (PointF)_Shape.Parts[0];
                                        mTransMatrix.TransformPoints(Pt);
                                        if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                        {
                                            gpSelShp.AddLine(new PointF(Pt[0].X - PtSize / 2, Pt[0].Y), new PointF(Pt[0].X + PtSize / 2, Pt[0].Y));
                                            gpSelShp.CloseFigure();
                                            gpSelShp.AddLine(new PointF(Pt[0].X, Pt[0].Y + PtSize / 2), new PointF(Pt[0].X, Pt[0].Y - PtSize / 2));
                                            gpSelShp.CloseFigure();
                                        }
                                        else
                                        {
                                            gpShp.AddLine(new PointF(Pt[0].X - PtSize / 2, Pt[0].Y), new PointF(Pt[0].X + PtSize / 2, Pt[0].Y));
                                            gpShp.CloseFigure();
                                            gpShp.AddLine(new PointF(Pt[0].X, Pt[0].Y + PtSize / 2), new PointF(Pt[0].X, Pt[0].Y - PtSize / 2));
                                            gpShp.CloseFigure();
                                        }
                                    }
                                }
                                else if (_Layer.MarkerStyle == MarkerStyle.Custom)
                                {
                                    Font _MFnt = new Font(_Layer.MarkerFont.FontFamily, PtSize);
                                    while (dicEnumerator.MoveNext())
                                    {
                                        //*** Traverse Shapes
                                        _Shape = (Shape)dicEnumerator.Value;
                                        Pt[0] = (PointF)_Shape.Parts[0];
                                        mTransMatrix.TransformPoints(Pt);
                                        if (_Layer.SelectedArea.Contains(_Shape.AreaId))
                                        {
                                            g.DrawString((string)_Layer.MarkerChar.ToString(), _MFnt, BrSelection, Pt[0].X, Pt[0].Y, _StringFormat);

                                        }
                                        else
                                        {
                                            g.DrawString(_Layer.MarkerChar.ToString(), _MFnt, BrLayer, Pt[0].X, Pt[0].Y, _StringFormat);
                                        }
                                    }
                                    _MFnt.Dispose();
                                }

                                g.FillPath(BrLayer, gpShp);
                                g.DrawPath(PnLayer, gpShp);
                                g.FillPath(BrSelection, gpSelShp);
                                g.DrawPath(PnSelection, gpSelShp);
                                Pt = null;
                                PnLayer.Dispose();
                                BrLayer.Dispose();
                                g.SmoothingMode = SmoothingMode.None;
                                break;
                        }
                    }
                }
            }
            gpShp.Dispose();
            gpSelShp.Dispose();
            _StringFormat.Dispose();
            BrSelection.Dispose();
            PnSelection.Dispose();
            // _Layer = null;
            _Shape = null;
        }
Пример #31
0
 protected override void OnPaint(PaintEventArgs e)
 {
     if (DesignMode)
     {
         Graphics gr = e.Graphics;
         {
             HatchBrush hb = null;
             Pen p = null;
             try
             {
                 switch (this.FileDlgStartLocation)
                 {
                     case AddonWindowLocation.Right:
                         hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red);
                         p = new Pen(hb, 5);
                         gr.DrawLine(p, 0, 0, 0, this.Height);
                         break;
                     case AddonWindowLocation.Bottom:
                         hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red);
                         p = new Pen(hb, 5);
                         gr.DrawLine(p, 0, 0, this.Width, 0);
                         break;
                     case AddonWindowLocation.BottomRight:
                     default:
                         hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red);
                         p = new Pen(hb, 5);
                         gr.DrawLine(p, 0, 0, 4, 4);
                         break;
                 }
             }
             finally
             {
                 if (p != null)
                     p.Dispose();
                 if (hb != null)
                     hb.Dispose();
             }
         }
     }
     base.OnPaint(e);
 }
Пример #32
0
        private Bitmap GenerateImagePrivate()
        {
            Font font;
            Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                RectangleF rectF = new RectangleF(0f, 0f, this.width, this.height);
                Rectangle rect = new Rectangle(0, 0, this.width, this.height);
                HatchBrush smallConfettiBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
                graphics.FillRectangle(smallConfettiBrush, rect);
                float previousWidth = 0f;
                float size = Convert.ToInt32((this.height * 0.8));
                while (true)
                {
                    font = new System.Drawing.Font(this.fontFamilyName, size, FontStyle.Bold);
                    SizeF textSize = graphics.MeasureString(this.Text, font);
                    if (textSize.Width <= this.width)
                    {
                        break;
                    }
                    if (previousWidth > 0f)
                    {
                        int estimatedSize = Convert.ToInt32(((textSize.Width - this.width) / (previousWidth - textSize.Width)));
                        if (estimatedSize > 0)
                        {
                            size -= estimatedSize;
                        }
                        else
                        {
                            size -= 1f;
                        }
                    }
                    else
                    {
                        size -= 1f;
                    }
                    previousWidth = textSize.Width;
                }
                size += 4f;

                font = new System.Drawing.Font(this.fontFamilyName, size, FontStyle.Bold);
                StringFormat format = new StringFormat();
                format.Alignment = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                GraphicsPath textPath = new GraphicsPath();
                textPath.AddString(this.Text, font.FontFamily, (int)font.Style, font.Size, rect, format);
                if (this.FontWarp != FontWarpFactor.None)
                {
                    int warpDivisor = 0;
                    switch (this._fontWarp)
                    {
                        case FontWarpFactor.Low:
                            warpDivisor = 6;
                            break;

                        case FontWarpFactor.Medium:
                            warpDivisor = 5;
                            break;

                        case FontWarpFactor.High:
                            warpDivisor = 4;
                            break;

                        case FontWarpFactor.Extreme:
                            warpDivisor = 3;
                            break;
                    }
                    int heightRange = Convert.ToInt32((((double)rect.Height) / ((double)warpDivisor)));
                    int widthRange = Convert.ToInt32((((double)rect.Width) / ((double)warpDivisor)));
                    PointF point1 = this.RandomPoint(0, widthRange, 0, heightRange);
                    PointF point2 = this.RandomPoint(rect.Width - (widthRange - Convert.ToInt32(point1.X)), rect.Width, 0, heightRange);
                    PointF point3 = this.RandomPoint(0, widthRange, rect.Height - (heightRange - Convert.ToInt32(point1.Y)), rect.Height);
                    PointF point4 = this.RandomPoint(rect.Width - (widthRange - Convert.ToInt32(point3.X)), rect.Width, rect.Height - (heightRange - Convert.ToInt32(point2.Y)), rect.Height);
                    PointF[] points = new PointF[] { point1, point2, point3, point4 };
                    Matrix matrix = new Matrix();
                    matrix.Translate(0f, 0f);
                    textPath.Warp(points, rectF, matrix, WarpMode.Perspective, 0f);
                }
                HatchBrush largeConfettiBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
                graphics.FillPath(largeConfettiBrush, textPath);

                int maxDimension = Math.Max(rect.Width, rect.Height);
                int steps = Convert.ToInt32((((double)(rect.Width * rect.Height)) / 30));
                for (int i = 0; i <= steps; i++)
                {
                    graphics.FillEllipse(largeConfettiBrush, this.random.Next(rect.Width), this.random.Next(rect.Height), this.random.Next(Convert.ToInt32((((double)maxDimension) / 50))), this.random.Next(Convert.ToInt32((((double)maxDimension) / 50))));
                }
                font.Dispose();
                largeConfettiBrush.Dispose();
                graphics.Dispose();
            }
            return bitmap;
        }
Пример #33
0
        public void GenerateImage()
        {
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, this.width, this.height);

            // Fill in the background.
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.FromArgb(114, 172, 236), Color.FromArgb(161, 214, 255));
            //Color.FromArgb(76,136,198)    medium
            //Color.FromArgb(0,79,136)      dark
            //Color.FromArgb(114,172,236)   medium-light
            //Color.FromArgb(135,188,254)   light
            //Color.FromArgb(161,214,255)   really light

            g.FillRectangle(hatchBrush, rect);

            // Set up the text font.
            SizeF size;
            float fontSize = rect.Height + 4;
            Font font;
            // Adjust the font size until the text fits within the image.
            do
            {
                fontSize--;
                font = new Font(this.familyName, fontSize, FontStyle.Bold);
                size = g.MeasureString(this.text, font);
            } while (size.Width > rect.Width);

            // Set up the text format.
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            // Create a path using the text and warp it randomly.
            GraphicsPath path = new GraphicsPath();
            path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
            float v = 4F;
            PointF[] points =
                {
                    new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
                    new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
                    new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
                    new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
                };
            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            // Draw the text.
            hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.FromArgb(0, 79, 136), Color.FromArgb(76, 136, 198));
            g.FillPath(hatchBrush, path);

            // Add some random noise.
            int m = 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;
        }
Пример #34
0
        // ====================================================================
        // Creates the bitmap image.
        // ====================================================================
        /// <summary>
        /// Generates the image.
        /// </summary>
        private void GenerateImage()
        {
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(0, 0, Width, Height);

            // Fill in the background.
            HatchBrush hatchBrush = new HatchBrush(RandomHatchStyle, Color.WhiteSmoke, Color.LightGray);

            g.FillRectangle(hatchBrush, rect);

            // Set up the text font.
            SizeF size;
            float fontSize = rect.Height + 1;
            Font font;

            // Adjust the font size until the text fits within the image.
            do
            {
                fontSize--;
                font = new Font(FontFamily, fontSize, FontStyle.Regular);
                size = g.MeasureString(Text, font);
            } while (size.Width > rect.Width);

            // Set up the text format.
            StringFormat format = new StringFormat { Alignment = RandomStringAlignment, LineAlignment = RandomStringAlignment };

            // Create a path using the text and warp it randomly.
            GraphicsPath path = new GraphicsPath();
            path.AddString(Text, font.FontFamily, (int)font.Style, font.Size, rect, format);
            const float v = 4F;
            PointF[] points =  {
                                   new PointF(Randomizer.NextNumber(rect.Width) / v, Randomizer.NextNumber(rect.Height) / v),
                                   new PointF(rect.Width - Randomizer.NextNumber(rect.Width) / v, Randomizer.NextNumber(rect.Height) / v),
                                   new PointF(Randomizer.NextNumber(rect.Width) / v,rect.Height - Randomizer.NextNumber(rect.Height) / v),
                                   new PointF(rect.Width - Randomizer.NextNumber(rect.Width) / v,rect.Height - Randomizer.NextNumber(rect.Height) / v)
                               };

            Matrix matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            // Draw the text.
            hatchBrush = new HatchBrush(RandomHatchStyle, Color.Gray, Color.LightGray);
            g.FillPath(hatchBrush, path);

            // Add some random noise.
            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
            {
                int x = Randomizer.NextNumber(rect.Width);
                int y = Randomizer.NextNumber(rect.Height);
                int w = Randomizer.NextNumber(m / 50);
                int h = Randomizer.NextNumber(m / 50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }

            Brush brush = new SolidBrush(Color.FromArgb(100, 68, 68, 68));
            g.FillPath(brush, path);

            const double distort = 8d;

            // Copy the image so that we're always using the original for source color
            using (Bitmap copy = (Bitmap)bitmap.Clone())
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        // Adds a simple wave
                        int newX = (int)(x + (distort * Math.Sin(Math.PI * y / 84.0)));
                        int newY = (int)(y + (distort * Math.Cos(Math.PI * x / 44.0)));
                        if (newX < 0 || newX >= Width) newX = 0;
                        if (newY < 0 || newY >= Height) newY = 0;
                        bitmap.SetPixel(x, y, copy.GetPixel(newX, newY));
                    }
                }
            }

            // Clean up.
            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();

            // Set the image.
            Image = bitmap;
        }