在过去的几周里,我一直在创建一个程序来创建一个有网格的位图,每次我想要更改图像时,我都会用
重新创建它。 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
但有更简单的方法吗?因为目前每次重新创建图像似乎非常密集,并且需要一两秒来更新图像,这是我不想要的,我希望它尽可能快地接近表格,但我无法弄清楚如何“增加”网格的宽度,而不重新创建整个图像,这需要时间。
我已经尝试了一个后台工作者,但它确实没什么区别,因为图像需要很长时间。
欢迎任何想法和建议!
由于