本文整理汇总了C#中System.Drawing.Drawing2D.Matrix.Translate方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Translate方法的具体用法?C# Matrix.Translate怎么用?C# Matrix.Translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.Matrix
的用法示例。
在下文中一共展示了Matrix.Translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:CalculateCenterOfSubShapes
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Shapes();
// Load Visio diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// Get a group shape by ID and page index is 0
Shape shape = diagram.Pages[0].Shapes.GetShape(795);
// Get a sub-shape of the group shape by id
Shape subShape = shape.Shapes.GetShape(794);
Matrix m = new Matrix();
// Apply the translation vector
m.Translate(-(float)subShape.XForm.LocPinX.Value, -(float)subShape.XForm.LocPinY.Value);
// Set the elements of that matrix to a rotation
m.Rotate((float)subShape.XForm.Angle.Value);
// Apply the translation vector
m.Translate((float)subShape.XForm.PinX.Value, (float)subShape.XForm.PinY.Value);
// Get pinx and piny
double pinx = m.OffsetX;
double piny = m.OffsetY;
// Calculate the sub-shape pinx and piny
double resultx = shape.XForm.PinX.Value - shape.XForm.LocPinX.Value - pinx;
double resulty = shape.XForm.PinY.Value - shape.XForm.LocPinY.Value - piny;
// ExEnd:CalculateCenterOfSubShapes
}
示例2: DrawEffectImage
public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel)
{
int step = 1;
Graphics bg;
Bitmap doubleBufferingBitmap;
SolidBrush solidBrush;
Rectangle rectangle;
Matrix matrix = null;
try
{
doubleBufferingBitmap = new Bitmap(current); // ダブルバッファリング用画面
bg = Graphics.FromImage(doubleBufferingBitmap); // ダブルバッファリング用画面描画用Graphics
solidBrush = new SolidBrush(System.Drawing.Color.Black);
rectangle = new Rectangle(0, 0, current.Width, current.Height);
matrix = new Matrix();
step = doubleBufferingBitmap.Width / 50;
if (step < 1)
{
step = 1;
}
ResetInterval();
for (int x = 0; x < doubleBufferingBitmap.Width; x += step)
{
bg.ResetTransform(); // リセット座標変換
bg.FillRectangle(solidBrush, rectangle);
// current画像
matrix.Reset();
matrix.Translate(x, 0, MatrixOrder.Append); // 原点移動
bg.Transform = matrix; // 座標設定
bg.DrawImage(current, 0, 0);
// next画像
matrix.Reset();
matrix.Translate(x - doubleBufferingBitmap.Width, 0, MatrixOrder.Append);
bg.Transform = matrix;
bg.DrawImage(next, 0, 0);
effecingPanel.pictureBox.Image = doubleBufferingBitmap;
effecingPanel.pictureBox.Refresh();
DoEventAtIntervals();
}
matrix.Dispose();
bg.Dispose();
doubleBufferingBitmap.Dispose();
effecingPanel.pictureBox.Image = next;
}
catch (SystemException ex)
{
Console.WriteLine(ex.Message);
}
}
示例3: CalcTransform
private void CalcTransform()
{
Matrix m = new Matrix();
m.Translate(Width / 2, Height / 2);
m.Scale((float)zoom, (float)zoom);
m.Translate(offset.X, offset.Y);
transform = m;
itransform = m.Clone();
itransform.Invert();
}
示例4: QuotePartButton
public QuotePartButton(float scaleX, float scaleY, BrushesStorage brushes, PenStorage pens, bool isLeft = true)
{
brushesStor = brushes;
pensStor = pens;
colorScheme.Add(ButtonFigureColorScheme.Normal, Color.FromArgb(255, 180, 247, 180));
colorScheme.Add(ButtonFigureColorScheme.Pressed, Color.FromArgb(255, 200, 247, 210));
colorScheme.Add(ButtonFigureColorScheme.Light, Color.FromArgb(255, 160, 195, 180));
currentBrush = brushesStor.GetBrush(colorScheme[ButtonFigureColorScheme.Normal]) as SolidBrush;
ScaleX = scaleX;
ScaleY = scaleY;
this.isLeft = isLeft;
translateMatrix = new Matrix();
string buySellIndicatorHaderText;
if (isLeft)
{
translateMatrix.Translate(paddingLeftRightProportion / 2, PaddingTopProportion);
buySellIndicatorHaderText = "Bid";
}
else
{
translateMatrix.Translate(QuotePartButtonFigure.OriginalWidth * 2 + paddingLeftRightProportion / 2, PaddingTopProportion);
translateMatrix.Scale(-1, 1);
buySellIndicatorHaderText = "Ask";
}
buySellIndicator = new BuySellIndicator
{
ScaleX = scaleX,
ScaleY = scaleY,
OriginalLocation = isLeft
?
new Point(
Convert.ToInt32(paddingLeftRightProportion),
Convert.ToInt32(PaddingTopProportion + PaddingTopBuySellIndicator))
:
new Point(
Convert.ToInt32(QuotePartButtonFigure.OriginalWidth + paddingLeftRightProportion),
Convert.ToInt32(PaddingTopProportion + PaddingTopBuySellIndicator)),
HaderText = buySellIndicatorHaderText,
Volume = null
};
arrowTrend = new ArrowTrend
{
Sx = ScaleX,
Sy = ScaleY,
Brushes = brushes,
Pens = pens,
OriginalLocation = isLeft ? new PointF(QuotePartButtonFigure.OriginalWidth - paddingLeftRightProportion - 2, PaddingTopArrow) :
new PointF(QuotePartButtonFigure.OriginalWidth * 2 - paddingLeftRightProportion - 2, PaddingTopArrow)
};
}
示例5: InitializeBitmap
private void InitializeBitmap()
{
m_Bitmap = new Bitmap(m_PictureBox.Width, m_PictureBox.Height);
m_Graphics = Graphics.FromImage(m_Bitmap);
Matrix matrix = new Matrix();
matrix.Scale(1.0f, -1.0f);
matrix.Translate(m_OriginX, m_OriginY);
matrix.Translate(m_TranslationX, m_TranslationY);
matrix.Scale(m_ZoomFactor, m_ZoomFactor);
m_Graphics.Transform = matrix;
}
示例6: GetMatrix
static public Matrix GetMatrix (int index)
{
// not defined (-1) or first (0)
if (index <= 0)
return null;
Matrix m = new Matrix ();
switch (index) {
case 1:
// empty
break;
case 2:
m.Rotate (15);
break;
case 3:
m.RotateAt (45, new PointF (100, 100));
break;
case 4:
m.Scale (1.5f, 0.5f);
break;
case 5:
m.Shear (2.0f, 2.0f);
break;
case 6:
m.Translate (50, 50);
break;
}
return m;
}
示例7: TankPolygonPoints
/// <summary>
/// Returned points 1-4 are the left track, points 5-8 are the right track, 9-16 are the turret
/// They should be drawn individually
/// </summary>
public static PointF[] TankPolygonPoints(int offsetX, int offsetY, float rotDegrees, float size)
{
var points = new PointF[16] {
// Left track
new PointF(-1, -1),
new PointF(-1, 1),
new PointF(-0.5f, 1),
new PointF(-0.5f, -1),
// Right track
new PointF(0.5f, -1),
new PointF(1, -1),
new PointF(1, 1),
new PointF(0.5f, 1),
// Turret
new PointF(-0.5f, -0.5f),
new PointF(0.5f, -0.5f),
new PointF(-0.5f, 0.5f),
new PointF(-0.25f, 0.5f),
new PointF(-0.25f, 1.75f),
new PointF(0.25f, 1.75f),
new PointF(0.25f, 0.5f),
new PointF(0.5f, 0.5f)
};
var matrix = new Matrix();
matrix.Rotate(rotDegrees, MatrixOrder.Append);
matrix.Translate(offsetX, offsetY, MatrixOrder.Append);
matrix.Scale(size, size);
matrix.TransformPoints(points);
return points;
}
示例8: ApplyRegionPathToImage
public static Image ApplyRegionPathToImage(Image backgroundImage, GraphicsPath regionFillPath, RegionCaptureOptions options)
{
if (backgroundImage != null && regionFillPath != null)
{
Image img;
Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds());
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle);
using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone())
{
using (Matrix matrix = new Matrix())
{
gp.CloseFigure();
matrix.Translate(-Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y));
gp.Transform(matrix);
}
img = ImageHelpers.CropImage(backgroundImage, newRegionArea, gp);
}
return img;
}
return null;
}
示例9: TransformPoints_DiagFirst
// Hack function to to diaonal flip first in transformations first
static public void TransformPoints_DiagFirst(PointF[] points, PointF origin, bool diagonal, bool horizontal, bool vertical)
{
Matrix translate = new Matrix();
Matrix rotate = new Matrix();
// Put the points into origin/local space
translate.Translate(-origin.X, -origin.Y);
translate.TransformPoints(points);
// Apply the flips/rotations
if (diagonal)
{
Matrix d = new Matrix(0, 1, 1, 0, 0, 0);
rotate.Multiply(d);
}
if (horizontal)
{
Matrix h = new Matrix(-1, 0, 0, 1, 0, 0);
rotate.Multiply(h);
}
if (vertical)
{
Matrix v = new Matrix(1, 0, 0, -1, 0, 0);
rotate.Multiply(v);
}
// Apply the combined flip/rotate transformation
rotate.TransformPoints(points);
// Put points back into world space
translate.Invert();
translate.TransformPoints(points);
}
示例10: GetCroppedScreenshot
public Image GetCroppedScreenshot()
{
using (Graphics g = Graphics.FromImage(Screenshot))
{
Region region = Manager.CombineAreas();
if (!region.IsEmpty(g))
{
RectangleF rect = region.GetBounds(g);
Bitmap bmp = new Bitmap((int)rect.Width, (int)rect.Height);
using (Graphics g2 = Graphics.FromImage(bmp))
{
g2.Clear(Color.Transparent);
using (Matrix translateMatrix = new Matrix())
{
translateMatrix.Translate(-rect.X, -rect.Y);
region.Transform(translateMatrix);
}
g2.IntersectClip(region);
g2.CompositingQuality = CompositingQuality.HighQuality;
g2.InterpolationMode = InterpolationMode.HighQualityBicubic;
g2.DrawImage(Screenshot, new Rectangle(0, 0, bmp.Width, bmp.Height), rect, GraphicsUnit.Pixel);
return bmp;
}
}
}
return null;
}
示例11: OnPaint
public override void OnPaint(PaintEventArgs e, ViewPortData viewPortData)
{
Graphics graphics = e.Graphics;
Bitmap memoryBitmap = viewPortData.MemoryBitmap;
Rectangle rect = new Rectangle(Point.Empty, memoryBitmap.Size);
graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, rect);
if (((base.parentView.RootDesigner != null) && (base.parentView.RootDesigner.Bounds.Width >= 0)) && (base.parentView.RootDesigner.Bounds.Height >= 0))
{
GraphicsContainer container = graphics.BeginContainer();
Matrix matrix = new Matrix();
matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
Point[] pts = new Point[] { viewPortData.LogicalViewPort.Location };
matrix.TransformPoints(pts);
matrix.Translate((float) (-pts[0].X + viewPortData.ShadowDepth.Width), (float) (-pts[0].Y + viewPortData.ShadowDepth.Height), MatrixOrder.Append);
graphics.Transform = matrix;
using (Region region = new Region(ActivityDesignerPaint.GetDesignerPath(base.parentView.RootDesigner, false)))
{
Region clip = graphics.Clip;
graphics.Clip = region;
AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
graphics.FillRectangle(Brushes.White, base.parentView.RootDesigner.Bounds);
if (ambientTheme.WorkflowWatermarkImage != null)
{
ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, base.parentView.RootDesigner.Bounds, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
}
graphics.Clip = clip;
}
graphics.EndContainer(container);
}
}
示例12: FlipImage
public static Image FlipImage(Image image, bool flipHorizontally, bool flipVertically)
{
Bitmap flippedImage = new Bitmap(image.Width, image.Height);
using (Graphics g = Graphics.FromImage(flippedImage))
{
//Matrix transformation
Matrix m = null;
if (flipVertically && flipHorizontally)
{
m = new Matrix(-1, 0, 0, -1, 0, 0);
m.Translate(flippedImage.Width, flippedImage.Height, MatrixOrder.Append);
}
else if (flipVertically)
{
m = new Matrix(1, 0, 0, -1, 0, 0);
m.Translate(0, flippedImage.Height, MatrixOrder.Append);
}
else if (flipHorizontally)
{
m = new Matrix(-1, 0, 0, 1, 0, 0);
m.Translate(flippedImage.Width, 0, MatrixOrder.Append);
}
//Draw
g.Transform = m;
g.DrawImage(image, 0, 0);
//clean up
m.Dispose();
}
return (Image)flippedImage;
}
示例13: RotateImage
public static Bitmap RotateImage(Image inputImg, double degreeAngle)
{
PointF[] pointF = new PointF[] { new PointF(0f, 0f), new PointF((float)inputImg.Width, 0f), new PointF(0f, (float)inputImg.Height), new PointF((float)inputImg.Width, (float)inputImg.Height) };
PointF[] rotationPoints = pointF;
PointMath.RotatePoints(rotationPoints, new PointF((float)inputImg.Width / 2f, (float)inputImg.Height / 2f), degreeAngle);
Rectangle bounds = PointMath.GetBounds(rotationPoints);
Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(rotatedBitmap);
try
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
Matrix m = new Matrix();
m.RotateAt((float)degreeAngle, new PointF((float)inputImg.Width / 2f, (float)inputImg.Height / 2f));
m.Translate((float)(-bounds.Left), (float)(-bounds.Top), MatrixOrder.Append);
g.Transform = m;
g.DrawImage(inputImg, 0, 0);
}
finally
{
if (g != null)
{
((IDisposable)g).Dispose();
}
}
return rotatedBitmap;
}
示例14: Translate
/*
* Translate
* методът се ползва при скалиране
* за нулиране на нежелан ефект при скалирнаето(изместване на фигурата в страни)
* и за нормално транслиране - преместване
* **/
public virtual void Translate(float X,float Y)
{
Matrix tempMatrix = new Matrix();
tempMatrix.Translate(X, Y);
tempMatrix.Multiply(TransformationMatrix);
TransformationMatrix = tempMatrix;
}
示例15: Form1_Paint
private void Form1_Paint(object sender, PaintEventArgs e)
{
using (Graphics g = e.Graphics)
{
// Создаем траекторию
GraphicsPath path = new GraphicsPath();
Rectangle rect = new Rectangle(20, 20, 150, 150);
path.AddRectangle(rect);
// Создаем градиентную кисть
PathGradientBrush pgBrush =
new PathGradientBrush(path.PathPoints);
// Уснинавливаем цвета кисти
pgBrush.CenterColor = Color.Red;
pgBrush.SurroundColors = new Color[] { Color.Blue };
// Создаем объект Matrix
Matrix X = new Matrix();
// Translate
X.Translate(30.0f, 10.0f, MatrixOrder.Append);
// Rotate
X.Rotate(10.0f, MatrixOrder.Append);
// Scale
X.Scale(1.2f, 1.0f, MatrixOrder.Append);
// Shear
X.Shear(.2f, 0.03f, MatrixOrder.Prepend);
// Применяем преобразование к траектории и кисти
path.Transform(X);
pgBrush.Transform = X;
// Выполняем визуализацию
g.FillPath(pgBrush, path);
}
}