Set Picture1.Picture = Pb1.ReadProperty("Picture")
是一种很慢的操作,而且还是在 Timer()事件中频繁被调用,会拖累整个程序。我还是建议 放弃使用 PropertyBag。
可以用以下代码测试一下:
测试前的准备:
1、在窗体中装2个picture,并使2个picture大小相同,最好尺寸调大点,测试效果会更明显。
2、picture 1 放一张图片,(随便什么图片 都行,最好是大图,不要16*16的小图标),picture 2保持原样(空白)。
程序代码:
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 Long) As Long
Private Sub Command1_Click()
Dim P As Long
Dim TTT As Single
TTT = Timer
For P = 0 To 100
Set Picture2.Picture = Picture1.Picture
Next
Debug.Print "Set xxx = yyy ,用时 = " & (Timer - TTT) * 1000
End Sub
Private Sub Command2_Click()
Dim P As Long
Dim TTT As Single
Dim PBag As New PropertyBag
PBag.WriteProperty "Picture", Picture1.Picture
TTT = Timer
For P = 0 To 100
Set Picture2.Picture = PBag.ReadProperty("Picture")
Next
Debug.Print "PropertyBag , 用时 = " & (Timer - TTT) * 1000
End Sub
Private Sub Command3_Click()
Dim P As Long
Dim TTT As Single
TTT = Timer
For P = 0 To 100
Call BitBlt(Picture2.hDc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hDc, 0, 0, vbSrcCopy)
Next
Debug.Print "BitBlt , 用时 = " & (Timer - TTT) * 1000
End Sub
看看哪种用时最长?