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


C# GraphicsPath.Transform方法代码示例

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


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

示例1: OnPaint

    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.CompositingMode = CompositingMode.SourceOver;

        GraphicsPath stroke = new GraphicsPath();
        stroke.AddString(this.Text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        string tmp = this.Text;
        while (stroke.GetBounds().Width > this.Width - 8) {
            tmp = tmp.Substring(0, tmp.Length - 1);
            stroke = new GraphicsPath();
            stroke.AddString(tmp + "...", this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        }

        RectangleF bounds = stroke.GetBounds();
        Matrix translationMatrix = new Matrix();
        if (this.TextAlign == ContentAlignment.TopRight || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.BottomRight) {
            translationMatrix.Translate(this.Width - bounds.Width - 8, 0);
        } else if (this.TextAlign == ContentAlignment.TopCenter || this.TextAlign == ContentAlignment.MiddleCenter || this.TextAlign == ContentAlignment.BottomCenter) {
            translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, 0);
        }
        if (this.TextAlign == ContentAlignment.MiddleLeft || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.MiddleCenter) {
            translationMatrix.Translate(0, (this.Height - bounds.Height - 5) / 2);
        } else if (this.TextAlign == ContentAlignment.BottomLeft || this.TextAlign == ContentAlignment.BottomCenter || this.TextAlign == ContentAlignment.BottomRight) {
            translationMatrix.Translate(0, (this.Height - bounds.Height - 5));
        }
        stroke.Transform(translationMatrix);
        e.Graphics.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
        e.Graphics.FillPath(Brushes.White, stroke); /* Text */
    }
开发者ID:klange,项目名称:acoustics-windows,代码行数:31,代码来源:TransparentLabel.cs

示例2: RandomWarp

    public GraphicsPath RandomWarp(GraphicsPath path)
    {
        // Add line //
        int PsCount = 10;
        PointF[] curvePs = new PointF[PsCount * 2];
        for (int u = 0; u < PsCount; u++)
        {
            curvePs[u].X = u * (Width / PsCount);
            curvePs[u].Y = Height / 2;
        }
        for (int u = PsCount; u < (PsCount * 2); u++)
        {
            curvePs[u].X = (u - PsCount) * (Width / PsCount);
            curvePs[u].Y = Height / 2 + 2;
        }

        double eps = Height * 0.05;

        double amp = rnd.NextDouble() * (double)(Height / 3);
        double size = rnd.NextDouble() * (double)(Width / 4) + Width / 8;

        double offset = (double)(Height / 3);

        PointF[] pn = new PointF[path.PointCount];
        byte[] pt = new byte[path.PointCount];

        GraphicsPath np2 = new GraphicsPath();

        GraphicsPathIterator iter = new GraphicsPathIterator(path);
        for (int i = 0; i < iter.SubpathCount; i++)
        {
            GraphicsPath sp = new GraphicsPath();
            bool closed;
            iter.NextSubpath(sp, out closed);

            Matrix m = new Matrix();
            m.RotateAt(Convert.ToSingle(rnd.NextDouble() * 30 - 15), sp.PathPoints[0]);

            m.Translate(-1 * i, 0);//uncomment

            sp.Transform(m);

            np2.AddPath(sp, true);
        }

        for (int i = 0; i < np2.PointCount; i++)
        {
            //pn[i] = Noise( path.PathPoints[i] , eps);
            pn[i] = Wave(np2.PathPoints[i], amp, size);
            pt[i] = np2.PathTypes[i];
        }

        GraphicsPath newpath = new GraphicsPath(pn, pt);

        return newpath;
    }
开发者ID:,项目名称:,代码行数:56,代码来源:

示例3: IsFit

    public bool IsFit(Point[] points)
    {
        // Note: rigorously calculating distance(point,ellipse) is very hard...
        // overlay the regions and compare the areas, for now.
        using (GraphicsPath polygp = new GraphicsPath())
        using (GraphicsPath elligp = new GraphicsPath())
        using (Matrix m = new Matrix())
        {
            // Set up gp for stroke.
            polygp.AddPolygon(points);

            // Set up gp for ellipse.
            elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);

            m.Translate((float)cx,(float)cy);
            m.Rotate((float)th);
            elligp.Transform(m);

            // Prepare regions for area-calculation.
            using (Region xor = new Region(elligp))
            using (Region isc = new Region(elligp))
            {
                xor.Xor(polygp);
                isc.Intersect(polygp);

                float badarea = Geometry.CalculateArea(xor);
                float iscarea = Geometry.CalculateArea(isc);
                float ratio = iscarea/badarea;

                //heuristic: 10.0 seems about right.
                return (ratio > 10f);
            }
        }
    }
开发者ID:pichiliani,项目名称:CoPhysicsSimulator,代码行数:34,代码来源:Ellipse.cs

示例4: updateClock

    /*
    private void updateClock() {
        lblSongTime.Text = timeToString(coolProgressBar1.Value) + " / " + timeToString(coolProgressBar1.Maximum);
        lblSongTime.Refresh();
    }
     */
    private void RenderText(Graphics g)
    {
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.CompositingMode = CompositingMode.SourceOver;

        String text = valueToString(this.Value) + " / " + valueToString(this.Maximum);

        GraphicsPath stroke = new GraphicsPath();
        stroke.AddString(text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        RectangleF bounds = stroke.GetBounds();
        /* Align right */
        Matrix translationMatrix = new Matrix();
        translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, (this.Height - bounds.Height - 5) / 2);
        stroke.Transform(translationMatrix);
        g.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
        g.FillPath(Brushes.White, stroke); /* Text */
    }
开发者ID:klange,项目名称:acoustics-windows,代码行数:24,代码来源:CoolProgressBar.cs


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