2

我不确定这个问题是否太微不足道,但是我需要使用以下方法的重载Graphics.DrawImage

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

我有一个RectangleF作为目标矩形,所以我需要将其转换RectangleFPointF[]MSDN 中的示例让我有点困惑,因为它只使用三个点来定义平行四边形。

我怎么能做到?

提前致谢

4

2 回答 2

2

好的,我在MSDN中找到了它:

destPoints 参数指定平行四边形的三个点。三个 PointF 结构表示平行四边形的左上角右上角左下角。从前三个点外推第四个点,形成一个平行四边形。

因此,您可以通过以下方式构造点数组:

    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)
        };
    }
于 2012-02-23T13:30:54.893 回答
2

您不能仅通过构造数组来创建它吗?

(根据记忆)其中 d 是目标 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) };
于 2012-02-22T20:19:34.960 回答