c# - 如何将 RectangleF 转换为 PointF[] 进行绘图?

标签 c# .net system.drawing drawing2d

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

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

我有一个 RectangleF 作为目标矩形,因此我需要将 RectangleF 转换为 PointF[]example in the MSDN让我有点困惑,因为它只使用三个点来定义平行四边形。

我该怎么做?

提前致谢

最佳答案

好的,我在 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.

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

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

关于c# - 如何将 RectangleF 转换为 PointF[] 进行绘图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9402224/

相关文章:

c# - 如何防止在执行打印预览时出现“打印进度”对话框

c# - Linq distinct 基于两列

c# - EF 中的动态搜索表达式问题

C# CSV 动态拆分

c# - Visual Studio的 "Add Service Reference"是如何反序列化对象的?

c# - MigraDoc 和 .NET Core 2.0

bitmap - Visual Studio 2017 中无法识别 System.Drawing.Bitmap

c# - 在 C# 中的一个操作中处理多个按钮操作

c# - 如何处理它在任务中创建的对象?

c# - 无法在带有输入字段 Unity 的 Scroll rect 中滚动