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

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

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

我怎样才能做到呢?

提前致谢

有帮助吗?

解决方案 2

好的,我在 微软软件定义网络:

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)
        };
    }

其他提示

难道不能只通过构建数组来创建它吗?

(凭记忆)其中 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) };
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top