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


C# GraphicsPath.Warp方法代码示例

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


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

示例1: Form2_Paint

        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            //패스 그래디언트
            Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) };
            PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile);
            e.Graphics.FillRectangle(B, ClientRectangle);

            //패스 그래디언트 끝
            //패스변형
            GraphicsPath Path = new GraphicsPath();
            Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat());
            //확장 후 외곽선 그리기
            Path.Widen(new Pen(Color.Black, 3));
            e.Graphics.DrawPath(Pens.Black, Path);

            //확장 후 채우기
            Path.Widen(new Pen(Color.Blue, 3));
            e.Graphics.DrawPath(Pens.Black, Path);

            //곡선 펴기
            Path.Flatten(new Matrix(), 12f);
            e.Graphics.DrawPath(Pens.Black, Path);

            //회전
            Matrix M = new Matrix();
            M.Rotate(-10);
            Path.Transform(M);
            e.Graphics.FillPath(Brushes.Blue, Path);

            //휘기
            RectangleF R = Path.GetBounds();
            PointF[] arPoint = new PointF[4];
            arPoint[0] = new PointF(R.Left, R.Top + 30);
            arPoint[1] = new PointF(R.Right, R.Top - 10);
            arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10);
            arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30);

            Path.Warp(arPoint, R);
            e.Graphics.FillPath(Brushes.Blue, Path);

            //클리핑

            //graphicspath path= new graphicspath();
            //path.fillmode = fillmode.winding;
            //path.addellipse(50, 10, 100, 80);
            //path.addellipse(20, 45, 160, 120);
            //e.graphics.fillpath(brushes.white, path);

            //e.graphics.setclip(path);

            //for (int y = 0; y < bottom; y+= 20)
            //{
            //    string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다";
            //    e.graphics.drawstring(str, font, brushes.blue, 0, y);
            //}

            //클리핑 끝
        }
开发者ID:sunnamkim,项目名称:doc,代码行数:58,代码来源:Form2.cs

示例2: 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

示例3: GenerateImage

 private void GenerateImage()
 {
     Font font;
     Bitmap bitmap = new Bitmap(width, height, (PixelFormat)0x26200a);
     Graphics graphics = Graphics.FromImage(bitmap);
     graphics.SmoothingMode = (SmoothingMode)4;
     Rectangle rectangle = new Rectangle(0, 0, width, height);
     HatchBrush brush = new HatchBrush((HatchStyle)0x22, Color.LightGray, Color.White);
     graphics.FillRectangle(brush, rectangle);
     float num = rectangle.Height + 1;
     do
     {
         num--;
         font = new Font(familyName, num, FontStyle.Bold);
     }
     while (graphics.MeasureString(text, font).Width > rectangle.Width);
     StringFormat format = new StringFormat();
     format.Alignment = (StringAlignment)1;
     format.LineAlignment = (StringAlignment)1;
     GraphicsPath path = new GraphicsPath();
     path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rectangle, format);
     const float num2 = 4f;
     PointF[] tfArray = new[] {
                                  new PointF((random.Next(rectangle.Width)) / num2,(random.Next(rectangle.Height)) / num2),
                                  new PointF(rectangle.Width - ((random.Next(rectangle.Width)) / num2),(random.Next(rectangle.Height) / num2)),
                                  new PointF((random.Next(rectangle.Width)) / num2,rectangle.Height - ((random.Next(rectangle.Height)) / num2)),
                                  new PointF(rectangle.Width - ((random.Next(rectangle.Width)) / num2),rectangle.Height - ((random.Next(rectangle.Height)) / num2)) 
                              };
     Matrix matrix = new Matrix();
     matrix.Translate(0f, 0f);
     path.Warp(tfArray, rectangle, matrix, 0, 0f);
     brush = new HatchBrush((HatchStyle)0x23, Color.LightGray, Color.DarkGray);
     graphics.FillPath(brush, path);
     int num3 = Math.Max(rectangle.Width, rectangle.Height);
     for (int i = 0; i < (((rectangle.Width * rectangle.Height)) / 30f); i++)
     {
         int num5 = random.Next(rectangle.Width);
         int num6 = random.Next(rectangle.Height);
         int num7 = random.Next(num3 / 50);
         int num8 = random.Next(num3 / 50);
         graphics.FillEllipse(brush, num5, num6, num7, num8);
     }
     font.Dispose();
     brush.Dispose();
     graphics.Dispose();
     Image = bitmap;
 }
开发者ID:sinaaslani,项目名称:kids.bmi.ir,代码行数:47,代码来源:CaptchaImage.cs

示例4: Generate

		/// <summary>
		/// 生成验证码并储存验证码到会话中
		/// </summary>
		public virtual Image Generate(string key, int digits = DefaultDigits, string chars = null) {
			// 生成验证码
			var captchaCode = RandomUtils.RandomString(digits, "23456789ABCDEFGHJKLMNPQRSTUWXYZ");
			var image = new Bitmap(digits * 20, 32);
			var imageRect = new Rectangle(0, 0, image.Width, image.Height);
			var font = new Font("Arial", 20, FontStyle.Regular);
			var brush = new SolidBrush(Color.Black);
			using (var graphic = Graphics.FromImage(image)) {
				// 描画背景
				HatchStyle backgroundStyle = (HatchStyle)RandomUtils.Generator.Next(18, 52);
				while (!Enum.IsDefined(typeof(HatchStyle), backgroundStyle)) {
					backgroundStyle = (HatchStyle)RandomUtils.Generator.Next(18, 52);
				}
				graphic.FillRectangle(
					new HatchBrush(backgroundStyle, Color.Gray, Color.White), imageRect);
				// 描画文本,然后不规则拉伸
				GraphicsPath path = new GraphicsPath();
				path.AddString(captchaCode, font.FontFamily, (int)font.Style, font.Size, imageRect,
					new StringFormat()
					{
						Alignment = StringAlignment.Center,
						LineAlignment = StringAlignment.Center
					});
				int padding = 5;
				Func<int> randomPadding = () => RandomUtils.Generator.Next(padding);
				var points = new PointF[] {
						new PointF(randomPadding(), randomPadding()),
						new PointF(image.Width - randomPadding(), randomPadding()),
						new PointF(randomPadding(), image.Height - randomPadding()),
						new PointF(image.Width - randomPadding(), image.Height - randomPadding()),
					};
				path.Warp(points, imageRect);
				graphic.FillPath(
					new HatchBrush(HatchStyle.LargeConfetti, Color.Black), path);
			}
			// 储存到会话,会话的过期时间最少是30分钟
			var sessionManager = Application.Ioc.Resolve<SessionManager>();
			var session = sessionManager.GetSession();
			session.Items[SessionItemKeyPrefix + key] = captchaCode;
			session.SetExpiresAtLeast(TimeSpan.FromMinutes(MakeSessionAliveAtLeast));
			sessionManager.SaveSession();
			// 返回图片对象
			return image;
		}
开发者ID:daywrite,项目名称:ZKWeb.Plugins,代码行数:47,代码来源:CaptchaManager.cs

示例5: Form1_Paint

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath Path = new GraphicsPath();
            Path.AddString("한글", new FontFamily("궁서"), 0, 100,
                new Point(10, 30), new StringFormat());

            /* 확장 후 외곽선 그리기
            Path.Widen(new Pen(Color.Black, 3));
            e.Graphics.DrawPath(Pens.Black, Path);
            //*/

            /* 확장 후 채우기
            Path.Widen(new Pen(Color.Black, 3));
            e.Graphics.FillPath(Brushes.Blue, Path);
            //*/

            /* 곡선 펴기
            Path.Flatten(new Matrix(), 12f);
            e.Graphics.DrawPath(Pens.Black, Path);
            //*/

            /* 회전
            Matrix M = new Matrix();
            M.Rotate(-10);
            Path.Transform(M);
            e.Graphics.FillPath(Brushes.Blue, Path);
            //*/

            //* 휘기
            RectangleF R = Path.GetBounds();
            PointF[] arPoint = new PointF[4];
            arPoint[0] = new PointF(R.Left, R.Top + 30);
            arPoint[1] = new PointF(R.Right, R.Top - 10);
            arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10);
            arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30);

            Path.Warp(arPoint, R);
            e.Graphics.FillPath(Brushes.Blue, Path);
            //*/
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:40,代码来源:Form1.cs

示例6: Create

        public override GraphicsPath Create(GraphicsPath path, XCaptcha.ICanvas canvas)
        {
            var random = new Random();
            var rect = new Rectangle(0, 0, canvas.Width, canvas.Height);

            const float wrapFactor = 8F;

            PointF[] points =
                {
                    new PointF(random.Next(rect.Width) / wrapFactor,random.Next(rect.Height) / wrapFactor),
                    new PointF(rect.Width - random.Next(rect.Width) / wrapFactor, random.Next(rect.Height) / wrapFactor),
                    new PointF(random.Next(rect.Width) / wrapFactor, rect.Height - random.Next(rect.Height) / wrapFactor),
                    new PointF(rect.Width - random.Next(rect.Width) / wrapFactor, rect.Height - random.Next(rect.Height) / wrapFactor)
                };

            var matrix = new Matrix();
            matrix.Translate(0F, 0F);

            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

            return path;
        }
开发者ID:ramirobr,项目名称:VestalisV3,代码行数:22,代码来源:XCaptchaConfiguration.cs

示例7: GenerateImage

        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;
        }
开发者ID:duongnhyt,项目名称:fit.nuce.edu.vn-1,代码行数:92,代码来源:Captcha.cs

示例8: GenerateImage

        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;
        }
开发者ID:htphongqn,项目名称:esell.yeuthietkeweb.com,代码行数:58,代码来源:RandomImage.cs

示例9: WarpText

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Warps the Text
		/// </summary>
		/// <param name="textPath">The Graphics Path for the text</param>
		/// <param name="rect">a rectangle which defines the image</param>
		/// <history>
		///     [cnurse]	03/17/2006	created
		/// </history>
		/// -----------------------------------------------------------------------------
		private static void WarpText(ref GraphicsPath textPath, Rectangle rect)
		{
			int intWarpDivisor;
			var rectF = new RectangleF(0, 0, rect.Width, rect.Height);

			intWarpDivisor = _Rand.Next(4, 8);

			int intHrange = Convert.ToInt32(rect.Height/intWarpDivisor);
			int intWrange = Convert.ToInt32(rect.Width/intWarpDivisor);

			PointF p1 = RandomPoint(0, intWrange, 0, intHrange);
			PointF p2 = RandomPoint(rect.Width - (intWrange - Convert.ToInt32(p1.X)), rect.Width, 0, intHrange);
			PointF p3 = RandomPoint(0, intWrange, rect.Height - (intHrange - Convert.ToInt32(p1.Y)), rect.Height);
			PointF p4 = RandomPoint(rect.Width - (intWrange - Convert.ToInt32(p3.X)), rect.Width, rect.Height - (intHrange - Convert.ToInt32(p2.Y)), rect.Height);

			var points = new[] {p1, p2, p3, p4};
			var m = new Matrix();
			m.Translate(0, 0);
			textPath.Warp(points, rectF, m, WarpMode.Perspective, 0);
		}
开发者ID:hungnt-me,项目名称:Dnn.Platform,代码行数:30,代码来源:CaptchaControl.cs

示例10: GenerateImage

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

示例11: 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

示例12: Warp_EmptyMatrix

		public void Warp_EmptyMatrix ()
		{
			PointF[] pts = new PointF[1] { new PointF (0, 0) };
			GraphicsPath path = new GraphicsPath ();
			path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
			RectangleF r = new RectangleF (10, 20, 30, 40);
			path.Warp (pts, r, new Matrix ());
			CheckWrap (path);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:GraphicsPathTest.cs

示例13: Wrap_Line

		public void Wrap_Line ()
		{
			using (GraphicsPath gp = new GraphicsPath ()) {
				gp.AddLine (new Point (1, 1), new Point (20, 20));
				Assert.AreEqual (2, gp.PointCount, "PointCount-1");

				PointF[] pts = new PointF[1] { new PointF (0, 0) };
				RectangleF r = new RectangleF (10, 20, 30, 40);
				gp.Warp (pts, r, new Matrix ());
				Assert.AreEqual (2, gp.PointCount, "PointCount-2");
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:12,代码来源:GraphicsPathTest.cs

示例14: Wrap_SinglePoint

		public void Wrap_SinglePoint ()
		{
			using (GraphicsPath gp = new GraphicsPath ()) {
				gp.AddLines (new Point[1] { new Point (1, 1) });
				// Special case - a line with a single point is valid
				Assert.AreEqual (1, gp.PointCount, "PointCount-1");

				PointF[] pts = new PointF[1] { new PointF (0, 0) };
				RectangleF r = new RectangleF (10, 20, 30, 40);
				gp.Warp (pts, r, new Matrix ());
				Assert.AreEqual (0, gp.PointCount, "PointCount-2");
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:GraphicsPathTest.cs

示例15: generateImage

        private void generateImage()
        {
            if (!isDirty) return;
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            using (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, backgroundDark, backgroundLight);
                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);
                    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);
                Matrix matrix = new Matrix();
                matrix.Translate(0F, 0F);
                if (System.Environment.OSVersion.Platform != PlatformID.Unix)
                {
                    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)
                    };
                    path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
                }
                else
                {
                    float xtr = (rect.Size.Width - size.Width)/2F+size.Width/10F;
                    float ytr = (rect.Size.Height - size.Height)/2F;
                    matrix.Rotate((float)random.NextDouble()*10F-5F);
                    matrix.Shear((float)random.NextDouble()*1F-0.5F,0F);
                    matrix.Translate(xtr,ytr);
                    path.Transform(matrix);
                }
                // Draw the text.
                using (hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, foregroundLight, foregroundDark))
                {
                    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();
            }

            // Set the image.
            image = bitmap;

            isDirty = false;
        }
开发者ID:jeremysimmons,项目名称:sixpack-library,代码行数:84,代码来源:CaptchaImage.cs


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