1,488
社区成员
发帖
与我相关
我的任务
分享
public function CreateBitmap(pic as picturebox) as long
dim mDc as long, mBitmap as long
mdc=CreateCompatibleDc(pic.hdc)
mBitmap=CreateCampatibleBitmap(pic.hdc,pic.scaleWidth,pic.scaleHeight)'假设pic.scalemode为pixel
selectObject mdc,mbitmap
CreateBitmap=mdc
end function
'此时mdc就是内存画布的dc,可以对他进行绘图操作
'需要时bitblt到图片的hdc上就ok了
Option Explicit
Private Sub DrawPicture()
Dim x As Long, y As Long
Randomize
Picture1.Cls
For x = 0 To Picture1.ScaleWidth - 1
For y = 0 To Picture1.ScaleHeight - 1
If Rnd() < 0.5 Then
Picture1.PSet (x, y)
End If
Next
Next
End Sub
'无缓冲的方式,图像逐渐显示'
Private Sub Command1_Click()
Picture1.AutoRedraw = False
DrawPicture
End Sub
'无缓冲的方式,图像一次显示'
Private Sub Command2_Click()
Picture1.AutoRedraw = True
DrawPicture
Picture1.Refresh
End Sub
Private Sub Form_Load()
Picture1.BackColor = vbWhite
Picture1.ForeColor = vbBlack
Picture1.ScaleMode = vbPixels
End Sub