本文整理匯總了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;
}
}