本文整理汇总了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);
}
示例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;
}
}