Прочитај на енглеском Уреди

Делите путем


Graphics.TransformPoints Method

Definition

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

Overloads

TransformPoints(CoordinateSpace, CoordinateSpace, Point[])

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

TransformPoints(CoordinateSpace, CoordinateSpace, PointF[])

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

TransformPoints(CoordinateSpace, CoordinateSpace, ReadOnlySpan<Point>)

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

TransformPoints(CoordinateSpace, CoordinateSpace, ReadOnlySpan<PointF>)

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

TransformPoints(CoordinateSpace, CoordinateSpace, Point[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, params System.Drawing.Point[] pts);
C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, System.Drawing.Point[] pts);

Parameters

destSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the destination coordinate space.

srcSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the source coordinate space.

pts
Point[]

Array of Point structures that represents the points to transformation.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates two points and draws a blue line between them.

  • Sets the world transform to translate by amounts 40 in the x direction and 30 in the y direction.

  • Transforms the points from world coordinates (World) to page coordinates (Page).

  • Resets the world transformation to the identity.

  • Draws a red line between the transformed points.

The result is a blue line and a translated red line below it.

C#
private void TransformPointsPoint(PaintEventArgs e)
{

    // Create array of two points.
    Point[] points = { new Point(0, 0), new Point(100, 50) };

    // Draw line connecting two untransformed points.
    e.Graphics.DrawLine(new Pen(Color.Blue, 3), points[0], points[1]);

    // Set world transformation of Graphics object to translate.
    e.Graphics.TranslateTransform(40, 30);

    // Transform points in array from world to page coordinates.
    e.Graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, points);

    // Reset world transformation.
    e.Graphics.ResetTransform();

    // Draw line that connects transformed points.
    e.Graphics.DrawLine(new Pen(Color.Red, 3), points[0], points[1]);
}

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

TransformPoints(CoordinateSpace, CoordinateSpace, PointF[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, params System.Drawing.PointF[] pts);
C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, System.Drawing.PointF[] pts);

Parameters

destSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the destination coordinate space.

srcSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the source coordinate space.

pts
PointF[]

Array of PointF structures that represent the points to transform.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates two points and draws a blue line between them.

  • Sets the world transform to translate by amounts 40 in the x direction and 30 in the y direction.

  • Transforms the points from world coordinates (World) to page coordinates (Page).

  • Resets the world transformation to the identity and draws a red line between the transformed points.

The result is a blue line and a translated red line below it.

C#
private void TransformPointsPointF(PaintEventArgs e)
{

    // Create array of two points.
    PointF[] points = { new PointF(0.0F, 0.0F), new PointF(100.0F, 50.0F) };

    // Draw line connecting two untransformed points.
    e.Graphics.DrawLine(new Pen(Color.Blue, 3), points[0], points[1]);

    // Set world transformation of Graphics object to translate.
    e.Graphics.TranslateTransform(40.0F, 30.0F);

    // Transform points in array from world to page coordinates.
    e.Graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, points);

    // Reset world transformation.
    e.Graphics.ResetTransform();

    // Draw line that connects transformed points.
    e.Graphics.DrawLine(new Pen(Color.Red, 3), points[0], points[1]);
}

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

TransformPoints(CoordinateSpace, CoordinateSpace, ReadOnlySpan<Point>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, scoped ReadOnlySpan<System.Drawing.Point> pts);

Parameters

destSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the destination coordinate space.

srcSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the source coordinate space.

pts
ReadOnlySpan<Point>

Array of PointF structures that represent the points to transform.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 9 (package-provided), 10 (package-provided)
Windows Desktop 9, 10

TransformPoints(CoordinateSpace, CoordinateSpace, ReadOnlySpan<PointF>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Transforms an array of points from one coordinate space to another using the current world and page transformations of this Graphics.

C#
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, scoped ReadOnlySpan<System.Drawing.PointF> pts);

Parameters

destSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the destination coordinate space.

srcSpace
CoordinateSpace

Member of the CoordinateSpace enumeration that specifies the source coordinate space.

pts
ReadOnlySpan<PointF>

Array of PointF structures that represent the points to transform.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 9 (package-provided), 10 (package-provided)
Windows Desktop 9, 10