2

I'm not sure if the question is too trivial but, I need to use the following overload of the method Graphics.DrawImage:

public void DrawImage(
    Image image,
    PointF[] destPoints,
    RectangleF srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr
)

I have a RectangleF as destination rectangle, so I need to convert the RectangleF to PointF[] but the example in the MSDN confused me a little bit because it only uses three points to define a parallelogram.

How could I do it?

Thanks in advance

Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
  • 1
    The reason they use three points is the `DrawImage` method calculates the fourth point based on the other three points to ensure a valid paralellagram. – Hand-E-Food Feb 22 '12 at 21:52

2 Answers2

3

Ok, I found it in the MSDN:

The destPoints parameter specifies three points of a parallelogram. The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth point is extrapolated from the first three to form a parallelogram.

So you can construct your point array in the following way:

    private PointF[] GetPoints(RectangleF rectangle)
    {
        return new PointF[3]
        { 
            new PointF(rectangle.Left, rectangle.Top),
            new PointF(rectangle.Right, rectangle.Top),
            new PointF(rectangle.Left, rectangle.Bottom)
        };
    }
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
2

Couldn't you create it by just constructing the array?

(From memory) Where d is the destination RectangleF:

destPoints[] = new PointF[4] { new PointF(d.Left, d.Top), new PointF(d.Right, d.Top), new PointF(d.Right, d.Bottom), new PointF(d.Left, d.Bottom) };
Ann L.
  • 13,760
  • 5
  • 35
  • 66