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


C# GraphicsPath.Transform方法代码示例

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


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

示例1: TransformExample

private void TransformExample(PaintEventArgs e)
{
             
    // Create a path and add and ellipse.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddEllipse(0, 0, 100, 200);
             
    // Draw the starting position to screen.
    e.Graphics.DrawPath(Pens.Black, myPath);
             
    // Move the ellipse 100 points to the right.
    Matrix translateMatrix = new Matrix();
    translateMatrix.Translate(100, 0);
    myPath.Transform(translateMatrix);
             
    // Draw the transformed ellipse to the screen.
    e.Graphics.DrawPath(new Pen(Color.Red, 2), myPath);
}
开发者ID:.NET开发者,项目名称:System.Drawing.Drawing2D,代码行数:18,代码来源:GraphicsPath.Transform

示例2: Font

//引入命名空间
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
   
class FontMenuForm: Form
{
     protected string strText = "Tall in the Center";
     protected Font font = new Font("Times New Roman", 24);
   
     public static void Main()
     {
          Application.Run(new FontMenuForm());
     }
     public FontMenuForm()
     {
          ResizeRedraw = true;
     }
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          GraphicsPath path = new GraphicsPath();
          float fFontSize = PointsToPageUnits(grfx, font);
   
          path.AddString(strText, font.FontFamily, (int) font.Style,
                         fFontSize, new PointF(0, 0), new StringFormat());
   
          RectangleF rectf = path.GetBounds();
   
          path.Transform(new Matrix(1, 0, 0, 1, 
                                    -(rectf.Left + rectf.Right) / 2,
                                    -(rectf.Top + rectf.Bottom) / 2));
          rectf = path.GetBounds();
          PointF[] aptf = path.PathPoints;
   
          for (int i = 0; i < aptf.Length; i++)
               aptf[i].Y *= 2 * (rectf.Width - Math.Abs(aptf[i].X)) / 
                                                                 rectf.Width; 
          path = new GraphicsPath(aptf, path.PathTypes);
   
          grfx.TranslateTransform(cx / 2, cy / 2);
          grfx.FillPath(new SolidBrush(clr), path);

                                            
     }
     public float GetAscent(Graphics grfx, Font font)
     {
          return font.GetHeight(grfx) * 
                    font.FontFamily.GetCellAscent(font.Style) /
                         font.FontFamily.GetLineSpacing(font.Style);
     }
     public float GetDescent(Graphics grfx, Font font)
     {
          return font.GetHeight(grfx) * 
                    font.FontFamily.GetCellDescent(font.Style) /
                         font.FontFamily.GetLineSpacing(font.Style);
     }
     public float PointsToPageUnits(Graphics grfx, Font font)
     {
          float fFontSize;
   
          if (grfx.PageUnit == GraphicsUnit.Display)
               fFontSize = 100 * font.SizeInPoints / 72;
          else
               fFontSize = grfx.DpiX * font.SizeInPoints / 72;
   
          return fFontSize;
     }
}
开发者ID:C#程序员,项目名称:System.Drawing.Drawing2D,代码行数:69,代码来源:GraphicsPath.Transform


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