怎样将PictureBox中的截屏信息存储为图片文件?
我存了后,总是灰色的底图,彩色信息存不住。
不知为什么?
'截屏
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hDC 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Sub CaptureScreen(Picture1 As PictureBox, xSrc As Long, ySrc As Long, wSrc As Long, hSrc As Long)
Dim wScreen As Long
Dim hScreen As Long
Dim w As Long
Dim h As Long
Dim hdcScreen As Long
Dim r As Long
Picture1.Cls
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY
Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
hdcScreen = GetDC(0)
r = StretchBlt(Picture1.hDC, 0, 0, w, h, hdcScreen, xSrc / Screen.TwipsPerPixelX, ySrc / Screen.TwipsPerPixelY, wSrc / Screen.TwipsPerPixelX, hSrc / Screen.TwipsPerPixelY, vbSrcCopy)
End Sub
'保存
Picture1.Picture = Picture1.Image
SavePicture Picture1, "c:\image.bmp"