为此,您可能需要使用TexureBrush
.
将TextureBrush
图像作为参数,这意味着您可以从磁盘加载现有图像,或者在内存中创建一个图像,您可以在其中绘制矩形等。
在以下示例中,GetTextureBrush 将创建实际的画笔。这是您定义颜色和形状的地方。我刚刚在你需要的车道上创建了一些东西,根据需要进行调整。
例如(VB.net):
Private Sub DrawBrush()
Dim g As Graphics = Me.CreateGraphics
Dim bmp As Image = GetTexureBrush
Dim b As New TextureBrush(bmp)
g.FillRectangle(b, New Rectangle(0, 0, 200, 500))
b.Dispose()
bmp.Dispose()
g.Dispose()
End Sub
Private Function GetTexureBrush() As Image
Dim bmp As New Bitmap(100, 20)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillRectangle(Brushes.DarkGreen, New Rectangle(0, 0, 75, 20))
g.FillRectangle(Brushes.Gray, New Rectangle(75, 0, 25, 20))
g.Dispose()
Return bmp
End Function
C#
private void DrawBrush()
{
Graphics g = this.CreateGraphics;
Image bmp = GetTexureBrush();
TextureBrush b = new TextureBrush(bmp);
g.FillRectangle(b, new Rectangle(0, 0, 200, 500));
b.Dispose();
bmp.Dispose();
g.Dispose();
}
private Image GetTexureBrush()
{
Bitmap bmp = new Bitmap(100, 20);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.DarkGreen, new Rectangle(0, 0, 75, 20));
g.FillRectangle(Brushes.Gray, new Rectangle(75, 0, 25, 20));
g.Dispose();
return bmp;
}