当前位置: 首页>>代码示例>>C#>>正文


C# HatchBrush.Dispose方法代码示例

本文整理汇总了C#中System.Drawing.Drawing2D.HatchBrush.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HatchBrush.Dispose方法的具体用法?C# HatchBrush.Dispose怎么用?C# HatchBrush.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Drawing2D.HatchBrush的用法示例。


在下文中一共展示了HatchBrush.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FillPath

 /// <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);
 }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:12,代码来源:HatchPattern.cs

示例2: ColorComboBox_DrawItem

		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();
			}
		}
开发者ID:gspatace,项目名称:logexpert,代码行数:29,代码来源:ColorComboBox.cs

示例3: CreateImages

        /*产生验证图片*/
        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();
        }
开发者ID:ViniciusConsultor,项目名称:noname-netshop,代码行数:32,代码来源:ValiateCode.aspx.cs

示例4: HatchBrushes_Paint

		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();
		}
开发者ID:ehershey,项目名称:development,代码行数:29,代码来源:HatchBrushes.cs

示例5: Build

        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;
        }
开发者ID:luqizheng,项目名称:OrnamentFramework,代码行数:57,代码来源:BubbleVerifyCodeBuilder.cs

示例6: PaintPath

        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();
            }
        }
开发者ID:x5lcfd,项目名称:bmfont-creator,代码行数:13,代码来源:HatchGlyphPainter.cs

示例7: DrawSelection

		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();
		}
开发者ID:AlexandrSurkov,项目名称:PKStudio,代码行数:17,代码来源:ElipseController.cs

示例8: OnPaint

        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();
        }
开发者ID:ErwanLent,项目名称:Origin-Theme-GDI-Library,代码行数:23,代码来源:MainGroupBox.cs

示例9: OnDrawItem

		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();
		}
开发者ID:ChrisMoreton,项目名称:Test3,代码行数:24,代码来源:HatchCombo.cs

示例10: Type2

		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;
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:72,代码来源:HipImageNew.aspx.cs

示例11: GenerateImage


//.........这里部分代码省略.........
      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;
    }
开发者ID:jiahello,项目名称:MyForum,代码行数:101,代码来源:CaptchaImage.cs

示例12: AddForegroundNoise

        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();
        }
开发者ID:jamescurran,项目名称:Castle.MonoRail.ViewComponents,代码行数:17,代码来源:CaptchaImage.cs

示例13: AddBackgroundNoise

 private void AddBackgroundNoise(Graphics graphics, Rectangle rect)
 {
     HatchBrush brush = new HatchBrush(HatchStyle.SmallConfetti, BackgroundNoiseColor, BackgroundColor);
     graphics.FillRectangle(brush, rect);
     brush.Dispose();
 }
开发者ID:jamescurran,项目名称:Castle.MonoRail.ViewComponents,代码行数:6,代码来源:CaptchaImage.cs

示例14: GenerateImage

        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.
//.........这里部分代码省略.........
开发者ID:pakerliu,项目名称:sharp-context,代码行数:101,代码来源:Program.cs

示例15: GenerateImage

        // ====================================================================
        // 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;
        }
开发者ID:chuckconway,项目名称:chucksoft.core,代码行数:97,代码来源:CaptchaImage.cs


注:本文中的System.Drawing.Drawing2D.HatchBrush.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。