本文整理汇总了C#中Matrix.Translate方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Translate方法的具体用法?C# Matrix.Translate怎么用?C# Matrix.Translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResimOlustur
private void ResimOlustur(int genislik, int yukseklik)
{
Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, genislik, yukseklik);
HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
g.FillRectangle(hatchBrush, rect);
SizeF size;
float fontSize = rect.Height + 1;
Font font;
do
{
fontSize--;
font = new Font(System.Drawing.FontFamily.GenericSerif.Name, fontSize, FontStyle.Bold);
size = g.MeasureString(this.text, font);
} while (size.Width > rect.Width);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
GraphicsPath path = new GraphicsPath();
path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
float v = 4F;
PointF[] points =
{
new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
};
Matrix matrix = new Matrix();
matrix.Translate(0F, 0F);
path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
g.FillPath(hatchBrush, path);
int m = Math.Max(rect.Width, rect.Height);
for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
{
int x = this.random.Next(rect.Width);
int y = this.random.Next(rect.Height);
int w = this.random.Next(m / 50);
int h = this.random.Next(m / 50);
g.FillEllipse(hatchBrush, x, y, w, h);
}
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
this.Image = bitmap;
}
示例2: 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 */
}
示例3: centerShipOnCanvas
public void centerShipOnCanvas()
{
Matrix translateMatrix = new Matrix();
translateMatrix.Translate(gameCanvas.Width / 2, gameCanvas.Height / 2);
playerShip.setEntityCenterX(gameCanvas.Width / 2);
playerShip.setEntityCenterY(gameCanvas.Height / 2);
playerShip.entityShape.RenderTransform = new MatrixTransform(translateMatrix);
}
示例4: Run
public static void Run()
{
// ExStart:AddDiagonalWatermarkToImage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
// Load an existing JPG image
using (Image image = Image.Load(dataDir + "SampleTiff1.tiff"))
{
// Declare a String object with Watermark Text
string theString = "45 Degree Rotated Text";
// Create and initialize an instance of Graphics class and Initialize an object of SizeF to store image Size
Graphics graphics = new Graphics(image);
SizeF sz = graphics.Image.Size;
// Creates an instance of Font, initialize it with Font Face, Size and Style
Font font = new Font("Times New Roman", 20, FontStyle.Bold);
// Create an instance of SolidBrush and set its various properties
SolidBrush brush = new SolidBrush();
brush.Color = Color.Red;
brush.Opacity = 0;
// Initialize an object of StringFormat class and set its various properties
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
// Create an object of Matrix class for transformation
Matrix matrix = new Matrix();
// First a translation then a rotation
matrix.Translate(sz.Width / 2, sz.Height / 2);
matrix.Rotate(-45.0f);
// Set the Transformation through Matrix
graphics.Transform = matrix;
// Draw the string on Image Save output to disk
graphics.DrawString(theString, font, brush, 0, 0, format);
image.Save(dataDir + "AddDiagonalWatermarkToImage_out.jpg");
}
// ExStart:AddDiagonalWatermarkToImage
}
示例5: DrawColorSlider
/// <summary>
/// Draws the colorslider control using passed colors.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
/// <param name="thumbOuterColorPaint">The thumb outer color paint.</param>
/// <param name="thumbInnerColorPaint">The thumb inner color paint.</param>
/// <param name="thumbPenColorPaint">The thumb pen color paint.</param>
/// <param name="barOuterColorPaint">The bar outer color paint.</param>
/// <param name="barInnerColorPaint">The bar inner color paint.</param>
/// <param name="barPenColorPaint">The bar pen color paint.</param>
/// <param name="elapsedOuterColorPaint">The elapsed outer color paint.</param>
/// <param name="elapsedInnerColorPaint">The elapsed inner color paint.</param>
private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint,
Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint,
Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint)
{
//set up thumbRect aproprietly
if (barOrientation == Orientation.Horizontal)
{
int TrackX = (((trackerValue - barMinimum) * (this.ContentRectangle.Width - thumbSize)) / (barMaximum - barMinimum)) + 2;
thumbRect = new Rectangle(TrackX, 3, thumbSize - 1, this.ContentRectangle.Height - 3);
}
else
{
int TrackY = (((trackerValue - barMinimum) * (this.ContentRectangle.Height - thumbSize)) / (barMaximum - barMinimum));
thumbRect = new Rectangle(3, TrackY, this.ContentRectangle.Width - 3, thumbSize - 1);
}
//adjust drawing rects
barRect = this.ContentRectangle;
thumbHalfRect = thumbRect;
LinearGradientMode gradientOrientation;
if (barOrientation == Orientation.Horizontal)
{
barRect.Inflate(-1, -barRect.Height / 3);
barHalfRect = barRect;
barHalfRect.Height /= 2;
gradientOrientation = LinearGradientMode.Vertical;
thumbHalfRect.Height /= 2;
elapsedRect = barRect;
elapsedRect.Width = thumbRect.Left + thumbSize / 2;
}
else
{
barRect.Inflate(-barRect.Width / 3, -1);
barHalfRect = barRect;
barHalfRect.Width /= 2;
gradientOrientation = LinearGradientMode.Horizontal;
thumbHalfRect.Width /= 2;
elapsedRect = barRect;
elapsedRect.Height = thumbRect.Top + thumbSize / 2;
}
//get thumb shape path
GraphicsPath thumbPath;
if (thumbCustomShape == null)
thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize);
else
{
thumbPath = thumbCustomShape;
Matrix m = new Matrix();
m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top);
thumbPath.Transform(m);
}
//draw bar
using (
LinearGradientBrush lgbBar =
new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation)
)
{
lgbBar.WrapMode = WrapMode.TileFlipXY;
e.Graphics.FillRectangle(lgbBar, barRect);
//draw elapsed bar
using (
LinearGradientBrush lgbElapsed =
new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint,
gradientOrientation))
{
lgbElapsed.WrapMode = WrapMode.TileFlipXY;
if (Selected && drawSemitransparentThumb)
{
Region elapsedReg = new Region(elapsedRect);
elapsedReg.Exclude(thumbPath);
e.Graphics.FillRegion(lgbElapsed, elapsedReg);
}
else
e.Graphics.FillRectangle(lgbElapsed, elapsedRect);
}
//draw bar band
using (Pen barPen = new Pen(barPenColorPaint, 0.5f))
{
e.Graphics.DrawRectangle(barPen, barRect);
}
}
//draw thumb
Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint;
if (Selected && drawSemitransparentThumb)
{
newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint);
//.........这里部分代码省略.........
示例6: update
public void update()
{
Matrix moveMatrix = new Matrix();
double radians = ConversionTools.degreesToRadians(this.bulletHeading);
double xMovement = Math.Cos(radians) * this.speed;
double yMovement = Math.Sin(radians) * this.speed;
this.setBulletX(xMovement + bulletX);
this.setBulletY(yMovement + bulletY);
this.setTotalX(xMovement += this.xTotalMovement);
this.setTotalY(yMovement += this.yTotalMovement);
moveMatrix.Translate(xMovement, yMovement);
//MessageBox.Show(bulletX.ToString() + " " + bulletY.ToString());
this.bulletShape.RenderTransform = new MatrixTransform(moveMatrix);
//this.handleWallCollisions();
//this.checkPlayerCollision();
}
示例7: 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 */
}
示例8: CreateRectangleSymbol
// Rectangle symbols may be translated into multiple symbols (if there is a grid).
Symbol[] CreateRectangleSymbol(OcadObject obj, LineSymDef symdef, RectangleInfo rectinfo)
{
List<Symbol> symlist = new List<Symbol>(); // list of symbols we're creating.
if (symdef == null)
throw new OcadFileFormatException("Object has unknown or inconsistent symbol type {0}", obj.Sym);
if (obj.coords == null || obj.coords.Length < 2)
return null;
// Create the main rectangle symbol.
// Determine size of the rectangle, and matrix needed to transform points to their correct location.
PointF[] pts = {PointFromOcadCoord(obj.coords[0]), PointFromOcadCoord(obj.coords[1]), PointFromOcadCoord(obj.coords[2]), PointFromOcadCoord(obj.coords[3])};
SizeF size = new SizeF(Util.DistanceF(pts[0], pts[1]), Util.DistanceF(pts[0], pts[3]));
float angle = Util.Angle(pts[0], pts[1]);
Matrix matrix = new Matrix();
matrix.Translate(pts[0].X, pts[0].Y);
matrix.Rotate(angle);
SymPath path;
PointKind[] kinds;
PointF[] pathpts;
if (rectinfo.cornerRadius == 0) {
kinds = new PointKind[] {PointKind.Corner, PointKind.Corner, PointKind.Corner, PointKind.Corner, PointKind.Corner};
pathpts = new PointF[] { new PointF(0,0), new PointF(0, size.Height), new PointF(size.Width, size.Height),
new PointF(size.Width, 0), new PointF(0,0)};
}
else {
kinds = new PointKind[] {PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
PointKind.Normal};
pathpts = new PointF[] { new PointF(rectinfo.cornerRadius, 0),
new PointF(size.Width - rectinfo.cornerRadius, 0),
new PointF(size.Width - (1-Util.kappa) * rectinfo.cornerRadius, 0),
new PointF(size.Width, (1-Util.kappa) * rectinfo.cornerRadius),
new PointF(size.Width, rectinfo.cornerRadius),
new PointF(size.Width, size.Height - rectinfo.cornerRadius),
new PointF(size.Width, size.Height - (1-Util.kappa) * rectinfo.cornerRadius),
new PointF(size.Width - (1-Util.kappa) * rectinfo.cornerRadius, size.Height),
new PointF(size.Width - rectinfo.cornerRadius, size.Height),
new PointF(rectinfo.cornerRadius, size.Height),
new PointF((1-Util.kappa) * rectinfo.cornerRadius, size.Height),
new PointF(0, size.Height - (1-Util.kappa) * rectinfo.cornerRadius),
new PointF(0, size.Height - rectinfo.cornerRadius),
new PointF(0, rectinfo.cornerRadius),
new PointF(0, (1-Util.kappa) * rectinfo.cornerRadius),
new PointF((1-Util.kappa) * rectinfo.cornerRadius, 0),
new PointF(rectinfo.cornerRadius, 0)};
}
pathpts = GraphicsUtil.TransformPoints(pathpts, matrix);
for (int i = 0; i < pathpts.Length; ++i)
pathpts[i] = new PointF((float) Math.Round(pathpts[i].X, 2), (float) Math.Round(pathpts[i].Y, 2)); // round to 2 decimals, so round trip to OCAD without change.
path = new SymPath(pathpts, kinds);
symlist.Add(new LineSymbol(symdef, path));
if (rectinfo.grid) {
if (size.Width > 0 && size.Height > 0) {
int cxCells = (int) Math.Round(size.Width / rectinfo.cellWidth);
if (cxCells < 1)
cxCells = 1;
int cyCells = (int) Math.Round(size.Height / rectinfo.cellHeight);
if (cyCells < 1)
cyCells = 1;
float width = size.Width / cxCells;
float height = size.Height / cyCells;
CreateGridLines(size, matrix, cxCells, cyCells, width, height, rectinfo.gridLines, symlist);
CreateGridText(size, matrix, angle, cxCells, cyCells, width, height, rectinfo, symlist);
}
}
return symlist.ToArray();
}
示例9: TranslationMatrix
// Create translation matrix.
public static Matrix TranslationMatrix(float dx, float dy)
{
#if false
Matrix m = Matrix.Identity;
m.TranslatePrepend(dx, dy);
return m;
#else
Matrix m = new Matrix();
m.Translate(dx, dy);
return m;
#endif
}
示例10: UpdateGP
protected internal override void UpdateGP()
{
// We keep the gp updated as we go; if it's already initialized, return.
if (gp != null) return;
else gp = new GraphicsPath();
// Establish the elliptical shape.
gp.AddEllipse(-MajorAxis,-MinorAxis,MajorAxis*2,MinorAxis*2);
using (Matrix m = new Matrix())
{
m.Translate(CenterPoint.X,CenterPoint.Y);
m.Rotate(Orientation);
gp.Transform(m);
}
// Reset the displacement matrix and clear associated caches.
if (displacement == null)
displacement = new Matrix();
else
displacement.Reset();
if (rgncache != null) rgncache.Dispose();
rgncache = null;
}
示例11: CalculatePostTransform
/// <summary>
/// Moves the origin to the center of the image.
/// </summary>
protected override void CalculatePostTransform(Matrix cumulativeTransform)
{
// shift center of model back from the origin after performing transform
var offset = SourceDimensions/2f + ModelOrigin;
cumulativeTransform.Translate(offset.X, offset.Y, offset.Z);
}
示例12: 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);
}
}
}
示例13: Test
/// <summary>
/// Some test code to check that there are no typing errors in the formulars.
/// </summary>
public static void Test()
{
XMatrix xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
Matrix m1 = new Matrix(23, -35, 837, 332, -3, 12);
DumpMatrix(xm1, m1);
XMatrix xm2 = new XMatrix(12, 235, 245, 42, 33, -56);
Matrix m2 = xm2.ToMatrix();
DumpMatrix(xm2, m2);
// xm1.Multiply(xm2, XMatrixOrder.Prepend);
// m1.Multiply(m2, MatrixOrder.Append);
xm1.Multiply(xm2, XMatrixOrder.Append);
m1.Multiply(m2, MatrixOrder.Append);
DumpMatrix(xm1, m1);
xm1.Translate(-243, 342, XMatrixOrder.Append);
m1.Translate(-243, 342, MatrixOrder.Append);
DumpMatrix(xm1, m1);
xm1.Scale(-5.66, 7.87);
m1.Scale(-5.66f, 7.87f);
// xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
// m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
DumpMatrix(xm1, m1);
xm1.Rotate(135, XMatrixOrder.Append);
m1.Rotate(135, MatrixOrder.Append);
// xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
// m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
DumpMatrix(xm1, m1);
xm1.RotateAt(177, new XPoint(-3456, 654), XMatrixOrder.Append);
m1.RotateAt(177, new PointF(-3456, 654), MatrixOrder.Append);
DumpMatrix(xm1, m1);
xm1.Shear(0.76, -0.87, XMatrixOrder.Prepend);
m1.Shear(0.76f, -0.87f, MatrixOrder.Prepend);
DumpMatrix(xm1, m1);
xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
m1 = new Matrix(23, -35, 837, 332, -3, 12);
XPoint[] xpoints = new XPoint[3]{new XPoint(23, 10), new XPoint(-27, 120), new XPoint(-87, -55)};
PointF[] points = new PointF[3]{new PointF(23, 10), new PointF(-27, 120), new PointF(-87, -55)};
xm1.TransformPoints(xpoints);
m1.TransformPoints(points);
xm1.Invert();
m1.Invert();
DumpMatrix(xm1, m1);
}
示例14: Move
internal override void Move(int dx, int dy, float da)
{
UpdateGP();
using (Matrix m = new Matrix())
{
// Rotate the whole force vector with body object.
PointF bodycg = new PointF(Body.Object.CG.X,Body.Object.CG.Y);
m.Translate(dx,dy);
m.RotateAt(da, bodycg);
gp.Transform(m);
// Adjust so that you are always the correct distance
// from the center of gravity.
Vector attachVector = Vector.FromPoint(Body.attachloc);
Point currentAttachPt =
new Point(MathEx.Round(gp.PathPoints[1].X), MathEx.Round(gp.PathPoints[1].Y));
Vector currentVector = Vector.FromPoints(Body.Object.CG, currentAttachPt);
double currentLength = currentVector.Length;
if (currentLength > 0)
{
Vector deltaVector = currentVector * (1 - attachVector.Length / currentLength);
// Adjust by this delta vector.
m.Reset();
m.Translate(-(int)deltaVector.DX, -(int)deltaVector.DY);
gp.Transform(m);
}
}
}
示例15: MoveNoStore
internal override void MoveNoStore(int dx, int dy, float da)
{
UpdateGP();
using (Matrix m = new Matrix())
{
m.Translate(dx,dy);
m.RotateAt(da, new PointF(CG.X,CG.Y));
gp.Transform(m);
displacement.Multiply(m,MatrixOrder.Append);
if (rgncache != null)
{
rgncache.Transform(m);
cgcache = Geometry.TransformPoint(m,cgcache);
}
}
}