在过去的几周里,我一直在开发一个程序,该程序可以创建一个上面有网格的位图,每次我想更改图像时,我都会重新创建它
gridBMP = New Bitmap(gridColumns * boxWidth, gridRows * boxHeight)
Dim g As Graphics = Graphics.FromImage(gridBMP)
Dim p As New Pen(Color.FromArgb(255, 0, 0, 0)) ' Create a new pen, black
Dim b As New SolidBrush(Color.FromArgb(255, 0, 0, 0)) ' Create a new solid brush, black
Dim wallPen As New Pen(Color.FromArgb(255, 192, 192, 192)) ' Create a new pen, Grey
Dim maxWidth As Integer = pb_grid.Width ' Get Max width
Dim maxHeight As Integer = pb_grid.Height ' Get Max height
g.Clear(Color.White) ' Make white background
For i = 0 To gridColumns ' Draw Column lines
Dim val As Integer = i * boxWidth
g.DrawLine(wallPen, New Point(val, 0), New Point(val, maxHeight))
Next
For i = 0 To gridRows ' Draw Row lines
Dim val As Integer = i * boxHeight
g.DrawLine(wallPen, New Point(0, val), New Point(maxWidth, val))
Next
' Draw borders at bottom and right
g.DrawLine(wallPen, New Point(0, maxHeight), New Point(maxWidth, maxHeight))
g.DrawLine(wallPen, New Point(maxWidth, 0), New Point(maxWidth, maxHeight))
drawAll(g, p, b) ' Draw all objects
pb_grid.Image = gridBMP
' Dispose of brush and pen
p.Dispose()
b.Dispose()
正如你在最后看到的,我将图片框图像设置为位图pb_grid.Image = gridBMP
但是有没有更简单的方法来做到这一点?因为目前每次重新创建图像似乎都非常密集,并且需要一两秒钟来更新图像,这是我不想要的,我希望它尽可能接近即时,但我不知道如何“增加”网格的宽度,而不需要重新创建整个图像,这需要时间。
我尝试过后台工作人员,但这真的没有什么区别,因为无论如何图像需要很长时间。
欢迎任何想法和建议!
谢谢