picturebox问题

123工艺品 2011-04-05 11:32:12
我在picturebox里画图,每0.5秒画一次,怎么图片老是闪烁呢?

'根据数组画图
Private Sub drawELS(ByVal x As Integer, ByVal y As Integer, ByVal s As Integer, ByVal z As Integer, ByVal a As Integer)
Dim picGraphics As System.Drawing.Graphics
Dim gr As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim sizeFK1 As Integer = 30
picGraphics = Graphics.FromImage(gr)
Dim i As Integer, j As Integer
Dim x1, y1 As Integer
For i = 0 To 18
For j = 1 To 12
If myFK.elsFKsuzu2(i, j) + myFK.elsFKsuzu(i, j) = 1 Then
x1 = (j - 1) * 30
y1 = i * 30
picGraphics.FillRectangle(myBrush, New Rectangle(x1, y1, sizeFK1, sizeFK1))
picGraphics.DrawLine(myFK.myFKforeC, x1, y1, x1 + sizeFK1, y1)
picGraphics.DrawLine(myFK.myFKforeC, x1 + sizeFK1, y1, x1 + sizeFK1, y1 + sizeFK1)
picGraphics.DrawLine(myFK.myFKforeC, x1, y1, x1, y1 + sizeFK1)
picGraphics.DrawLine(myFK.myFKforeC, x1, y1 + sizeFK1, x1 + sizeFK1, y1 + sizeFK1)
End If
Next
Next
Dim gg As Graphics
gg = PictureBox1.CreateGraphics
gg.Clear(Color.Black)
gg.SmoothingMode = Drawing2D.SmoothingMode.Default
gg.DrawImage(gr, 0, 0)
myBrush.Dispose()
picGraphics.Dispose()

End Sub

备注:数组是变化的
...全文
69 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
兔子-顾问 2011-04-06
  • 打赏
  • 举报
回复
既然自己解决了。分就给楼主了。自己无法给自己分,由我帮你结贴了。
123工艺品 2011-04-06
  • 打赏
  • 举报
回复
此问题已解决,不是位图大小问题.
其实是双缓冲画图问题,改正后代码如下:
'根据数组画图
Private Sub drawELS(ByVal x As Integer, ByVal y As Integer, ByVal s As Integer, ByVal z As Integer, ByVal a As Integer)
Dim picGraphics As System.Drawing.Graphics
Dim gr As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim sizeFK1 As Integer = 30
picGraphics = Graphics.FromImage(gr)
Dim i As Integer, j As Integer
Dim x1, y1 As Integer
For i = 0 To 18
For j = 1 To 12
If myFK.elsFKsuzu2(i, j) + myFK.elsFKsuzu(i, j) = 1 Then
x1 = (j - 1) * 30
y1 = i * 30
picGraphics.FillRectangle(myBrush, New Rectangle(x1, y1, sizeFK1, sizeFK1))
picGraphics.DrawLine(myFK.myFKforeC, x1, y1, x1 + sizeFK1, y1)
picGraphics.DrawLine(myFK.myFKforeC, x1 + sizeFK1, y1, x1 + sizeFK1, y1 + sizeFK1)
picGraphics.DrawLine(myFK.myFKforeC, x1, y1, x1, y1 + sizeFK1)
picGraphics.DrawLine(myFK.myFKforeC, x1, y1 + sizeFK1, x1 + sizeFK1, y1 + sizeFK1)
End If
Next
Next
picturebox1.image=gr
myBrush.Dispose()
picGraphics.Dispose()

End Sub
lhblxm 2011-04-06
  • 打赏
  • 举报
回复
Dim gr As New Bitmap(PictureBox1.Width, PictureBox1.Height)
生成的位图太大了,会占很多内存
改成Dim gr As New Bitmap(5, 5)试一下

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧