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