绘制纹理三角形

时间:2012-01-08 01:30:48

标签: c# winforms drawing system.drawing

我有一个图像和三个顶点及其位置和texcoord。

如何在图片框中绘制这个纹理三角形?

这是一张解释它是什么的图像:

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用GraphicsPathTextureBrush

// Create the triangle
GraphicsPath p = new GraphicsPath();
p.AddLine(triangleVertex1, triangleVertex2);
p.AddLine(triangleVertex2, triangleVertex3);
p.CloseFigure();

// Draw the triangle
Bitmap b = new Bitmap(pictureBox.ClientSize.Width, pictureBox.ClientSize.Height);

using(Graphics g = Graphics.FromImage(b), TextureBrush t = new TextureBrush(myImage)) {
    g.FillPath(t, p);
}

// Finally, set the PictureBox's image
pictureBox.Image = b;