无闪烁画图?在线
在picturebox上面画图,用的是paintpicture方法,
半分钟左右出现屏幕闪烁现象,怎么解决?
看别的帖子,好像可以通过双缓冲技术解决,
最好能提供详细的例子!谢谢
问题点数:100、回复次数:17Top
1 楼ynli2002(阿男)回复于 2005-08-22 14:19:14 得分 0
自己顶!Top
2 楼ynli2002(阿男)回复于 2005-08-22 15:29:08 得分 0
up!Top
3 楼ynli2002(阿男)回复于 2005-08-22 21:45:00 得分 0
怎么没有人回答!Top
4 楼VBDN( PowerBASIC.CN )回复于 2005-08-23 03:09:39 得分 0
先在一个隐藏的picturebox2上画;画完了,将隐藏picturebox2上的图片一次性paintpicture到picturebox1上,你看行么?Top
5 楼ynli2002(阿男)回复于 2005-08-23 11:51:16 得分 0
to VBDN(http://PowerBASIC.CN)
感谢你的回答,但还是有点闪Top
6 楼ynli2002(阿男)回复于 2005-08-23 16:06:03 得分 0
高人出来啊!Top
7 楼xinliangyu(yxl)回复于 2005-08-23 17:04:36 得分 0
须在内存DC中画Top
8 楼ynli2002(阿男)回复于 2005-08-23 17:25:07 得分 0
TO xinliangyu(yxl)
可否详细说明一下!Top
9 楼balloonman2002()回复于 2005-08-23 17:51:31 得分 50
画大图时不要用PAINTPICTURE,否则会有闪烁,建议在内存里创建DC,在内存DC里绘制后用BITBLT一次性绘到PICTURE控件,同时不显示的部分不需要BITBLT,只要把窗口显示部分BITBLT即可,这样可提高速度
总而言之一句话:所有操作尽量在内存操作完毕后再显示,这样可以极大提高速度Top
10 楼province_(雍昊)回复于 2005-08-23 19:13:36 得分 0
在内存DC里画,或者和VBDN说的那样在一个不可见的PICTUREBOX里画,画好后BITBLT到目标里就可以了。Top
11 楼ynli2002(阿男)回复于 2005-08-23 20:09:21 得分 0
原理我也懂,就是不知道具体用法
所以尽量给出详细一点的代码Top
12 楼TB0500636()回复于 2005-08-23 20:26:10 得分 0
up!Top
13 楼kmlxk(xiaoKKKK)回复于 2005-08-23 21:46:31 得分 50
我也不知道写的什么,不知lz有没有兴趣看看
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As RasterOpConstants) As Long 'create a new dc
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long ' delete a dc
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long 'load an image into an object (&H10 for load from file)
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long 'delete an object from memory
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long 'link to an object
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long 'see if a key is pressed
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'dc
Dim dogDC As Long
Dim dogMaskDC As Long
Dim bgDC As Long
Dim pathDC As Long
Dim restoreDC As Long
'dc
Dim lngDog As Long
Dim lngDogMask As Long
Dim lngBG As Long
Dim lngPath As Long
Dim lngRestore As Long
'/////////////////////////////////////////////////
Dim blnLeftPic As Boolean
Dim blnJumpUp As Boolean
Dim blnLeftPress As Boolean
Dim blnRightPress As Boolean
Dim lngJumpSpeed As Long
Dim bytStep As Byte
Dim kd As Byte
Dim xx As Long, yy As Long
Dim bytJumpTime As Byte
Const w As Long = 131
Const w2 As Long = 262
Const w3 As Long = 393
Const w4 As Long = 524
Const w5 As Long = 655
Const h As Long = 104
Const g = 4
Const conStep As Byte = 5
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
If blnLeftPic = True Then
BitBlt Me.hdc, xx, yy, w, h, bgDC, xx, yy, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w4, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w4, 0, vbSrcPaint
Me.Refresh
Else
BitBlt Me.hdc, xx, yy, w, h, bgDC, xx, yy, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w5, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w5, 0, vbSrcPaint
Me.Refresh
End If
End If
If KeyCode = vbKeyLeft Then
If GetPixel(pathDC, xx - conStep, yy - 10) <> RGB(0, 0, 0) Then
tmLeft.Enabled = True
End If
blnLeftPic = True
End If
If KeyCode = vbKeyRight Then
'If GetPixel(pathDC, xx + w + conStep, yy - 10) <> RGB(0, 0, 0) Then
tmRight.Enabled = True
'End If
blnLeftPic = False
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'// if SPACE is pressed, jump
If KeyAscii = vbKeySpace Then
If GetPixel(pathDC, xx, yy) <> RGB(0, 0, 0) And bytJumpTime < 1 Then
blnJumpUp = True
lngJumpSpeed = 30
bytJumpTime = bytJumpTime + 1
tmJump.Enabled = True
End If
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
If blnLeftPic = True Then
BitBlt Me.hdc, xx, yy, w, h, bgDC, xx, yy, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w, 0, vbSrcPaint
Me.Refresh
Else
BitBlt Me.hdc, xx, yy, w, h, bgDC, xx, yy, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w2, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w2, 0, vbSrcPaint
Me.Refresh
End If
End If
If KeyCode = vbKeyLeft Then
tmLeft.Enabled = False
End If
If KeyCode = vbKeyRight Then
tmRight.Enabled = False
End If
End Sub
Private Sub Form_Load()
blnLeftPic = True
xx = 480
yy = 130
dogDC = CreateCompatibleDC(Me.hdc)
dogMaskDC = CreateCompatibleDC(Me.hdc)
bgDC = CreateCompatibleDC(Me.hdc)
pathDC = CreateCompatibleDC(Me.hdc)
restoreDC = CreateCompatibleDC(Me.hdc)
'load the object pictures into the object variables
lngDog = LoadImage(0, App.Path & "\dog.bmp", 0, 0, 0, &H10)
lngDogMask = LoadImage(0, App.Path & "\dogm.bmp", 0, 0, 0, &H10)
lngBG = LoadImage(0, App.Path & "\bg1.bmp", 0, 0, 0, &H10)
lngPath = LoadImage(0, App.Path & "\bg1m.bmp", 0, 0, 0, &H10)
' 'link' objects to DCs
SelectObject dogDC, lngDog
SelectObject dogMaskDC, lngDogMask
SelectObject bgDC, lngBG
SelectObject pathDC, lngPath
SelectObject restoreDC, lngRestore
Me.ForeColor = RGB(255, 255, 255)
BitBlt Me.hdc, 0, 0, 640, 480, bgDC, 0, 0, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, bgDC, xx, yy, vbSrcCopy
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w, 0, vbSrcPaint
Me.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteDC dogDC
DeleteObject lngDog
DeleteDC dogMaskDC
DeleteObject lngDogMask
DeleteDC bgDC
DeleteObject lngBG
DeleteDC restoreDC
DeleteObject lngRestore
End Sub
Private Sub tmJump_Timer()
'Move
If blnJumpUp = True Then
lngJumpSpeed = lngJumpSpeed - g
yy = yy - lngJumpSpeed
Else
lngJumpSpeed = lngJumpSpeed + g
yy = yy + lngJumpSpeed
End If
'Draw
BitBlt Me.hdc, xx, yy - lngJumpSpeed, w, h + lngJumpSpeed + lngJumpSpeed, bgDC, xx, yy - lngJumpSpeed, vbSrcCopy
If blnLeftPic = True Then
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, 0, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, 0, 0, vbSrcPaint
Else
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w2, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w2, 0, vbSrcPaint
End If
Me.Refresh
'Judge
If lngJumpSpeed <= 0 Then
'lngJumpSpeed = 0
blnJumpUp = False
End If
If GetPixel(pathDC, xx, yy + h) = RGB(0, 0, 0) And blnJumpUp = False Then
lngJumpSpeed = 0
bytJumpTime = bytJumpTime - 1
tmJump.Enabled = False
End If
Me.Refresh
End Sub
Private Sub tmLeft_Timer()
Me.Refresh
xx = xx - conStep
BitBlt Me.hdc, xx, yy, w + conStep, h, bgDC, xx, yy, vbSrcCopy
If bytStep = 1 Then
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, 0, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, 0, 0, vbSrcPaint
bytStep = 0
Else
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w, 0, vbSrcPaint
bytStep = 1
End If
End Sub
Private Sub tmMain_Timer()
' If kd > 0 Then BitBlt restoreDC, 0, 0, w + 4, h + 4, Me.hdc, xx - 4, yy - 4, vbSrcCopy
If GetPixel(pathDC, xx, yy + h) <> RGB(0, 0, 0) Then
yy = yy + bytStep
Else
yy = yy - 1
End If
End Sub
Private Sub tmRight_Timer()
Me.Refresh
xx = xx + conStep
BitBlt Me.hdc, xx - conStep, yy, w + conStep, h, bgDC, xx - conStep, yy, vbSrcCopy
If bytStep = 1 Then
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w2, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w2, 0, vbSrcPaint
bytStep = 0
Else
BitBlt Me.hdc, xx, yy, w, h, dogMaskDC, w3, 0, vbSrcAnd
BitBlt Me.hdc, xx, yy, w, h, dogDC, w3, 0, vbSrcPaint
bytStep = 1
End If
End Sub
Top
14 楼ynli2002(阿男)回复于 2005-08-24 00:09:48 得分 0
upTop
15 楼balloonman2002()回复于 2005-08-24 08:35:21 得分 0
具体代码要自己写,下面的代码仅供参考:
http://blog.csdn.net/balloonman2002/archive/2005/06/22/400599.aspx
http://blog.csdn.net/balloonman2002/archive/2004/06/28/28697.aspxTop
16 楼WallesCai(女人之美,在于蠢得无怨无悔,男人之美,在于撒谎撒得白日见鬼)回复于 2005-08-31 20:11:00 得分 0
不是很明白,画图为什么要用到PAINTPICTURE,这个方法是用来贴图或者缩放用的,而画图则是用SETPIXEL或LINE等去做的。两者没有什么关系阿Top
17 楼province_(雍昊)回复于 2005-08-31 20:53:51 得分 0
在你全部画好后就用它使目标图显示你辛勤的劳动成果啊。Top




