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


C# GraphicsPath.Warp方法代码示例

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


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

示例1: ResimOlustur

    private void ResimOlustur(int genislik, int yukseklik)
    {
        Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb);

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

        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(System.Drawing.FontFamily.GenericSerif.Name, 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);
        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.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 = 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:,项目名称:,代码行数:59,代码来源:

示例2: GenerateImage

    // ====================================================================
    // Creates the bitmap image.
    // ====================================================================
    private 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.OutlinedDiamond, 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(this.familyName, fontSize, FontStyle.Strikeout);
            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.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 = 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;
    }
开发者ID:chevex-archived,项目名称:1PromotionalProducts,代码行数:72,代码来源:CaptchaImage.cs

示例3: WarpText

    private void WarpText(GraphicsPath textPath, Rectangle rect)
    {
        float num;
        float num2;
        switch (this._fontWarp)
        {
        case CaptchaImage.FontWarpFactor.Low:
            num = 6f;
            num2 = 1f;
            break;

        case CaptchaImage.FontWarpFactor.Medium:
            num = 5f;
            num2 = 1.3f;
            break;

        case CaptchaImage.FontWarpFactor.High:
            num = 4.5f;
            num2 = 1.4f;
            break;

        case CaptchaImage.FontWarpFactor.Extreme:
            num = 4f;
            num2 = 1.5f;
            break;
        case CaptchaImage.FontWarpFactor.None:
                default:
            return;

        }
                var r = num + num2;
                System.Diagnostics.Trace.WriteLine(r.ToString());
        RectangleF srcRect = new RectangleF(Convert.ToSingle(rect.Left), 0f, Convert.ToSingle(rect.Width), (float)rect.Height);
        int num3 = Convert.ToInt32((float)rect.Height / num);
        int num4 = Convert.ToInt32((float)rect.Width / num);
        checked
        {
            int num5 = rect.Left - Convert.ToInt32(unchecked((float)num4 * num2));
            int num6 = rect.Top - Convert.ToInt32(unchecked((float)num3 * num2));
            int num7 = rect.Left + rect.Width + Convert.ToInt32(unchecked((float)num4 * num2));
            int num8 = rect.Top + rect.Height + Convert.ToInt32(unchecked((float)num3 * num2));
            if (num5 < 0)
            {
                num5 = 0;
            }
            if (num6 < 0)
            {
                num6 = 0;
            }
            if (num7 > this.Width)
            {
                num7 = this.Width;
            }
            if (num8 > this.Height)
            {
                num8 = this.Height;
            }
            int arg_155_1 = num5;
            int arg_155_2 = num5 + num4;
            int num9 = num6 + num3;
            PointF pointF = this.RandomPoint(arg_155_1, arg_155_2, ref num6, ref num9);
            int arg_16E_1 = num7 - num4;
            int arg_16E_2 = num7;
            num9 = num6 + num3;
            PointF pointF2 = this.RandomPoint(arg_16E_1, arg_16E_2, ref num6, ref num9);
            int arg_184_1 = num5;
            int arg_184_2 = num5 + num4;
            num9 = num8 - num3;
            PointF pointF3 = this.RandomPoint(arg_184_1, arg_184_2, ref num9, ref num8);
            int arg_19B_1 = num7 - num4;
            int arg_19B_2 = num7;
            num9 = num8 - num3;
            PointF pointF4 = this.RandomPoint(arg_19B_1, arg_19B_2, ref num9, ref num8);
            PointF[] destPoints = new PointF[]
            {
                pointF,
                pointF2,
                pointF3,
                pointF4
            };
            Matrix matrix = new Matrix();
            matrix.Translate(0f, 0f);
            textPath.Warp(destPoints, srcRect, matrix, WarpMode.Perspective, 0f);
        }
    }
开发者ID:ascvorcov,项目名称:Captcha,代码行数:85,代码来源:CaptchaImage.cs


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