前几天我从网上找一个可以把截取屏幕界面到PictureBox的源代码,但我去不知如何把它保存为Jpg 或Bmp文件,曾经试过用"SavePicture Picture1.Picture"但也没用,因为可能是Picture1.Picture里面是为空的.所以无法保存.请各路高手指点迷津,在下感激不已!!!
(附源代码如下) 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
-------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim wScreen As Long
Dim hScreen As Long
Dim w As Long
Dim h As Long
Dim pic As PictureBox
Picture1.Cls
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY
Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
hdcScreen = GetDC(0)
p = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
End Sub
(附源代码如下) 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
-------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim wScreen As Long
Dim hScreen As Long
Dim w As Long
Dim h As Long
Dim pic As PictureBox
Picture1.Cls
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY
Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
hdcScreen = GetDC(0)
p = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
End Sub
解决方案 »
- 用户名是否正确都提示错误
- VB如何导入导出收藏夹
- 自定义下拉列表的问题(续)
- 请问在莞城的程序员有几位啊?
- *********超级麻烦问题,咱怎么让我的程序自动安装win2000/xp的FAX呀,并添加一个FAX打印机***
- 怎样打开MSDN?
- 如何获得文件的创建时间!!!!!!
- 想学编程不知道从哪里开头,哪位师傅指导一下
- KeyCode和KeyAscii有什么区别,为什么KeyPress(KeyAscii As Integer)事件和KeyDown(KeyCode As Integer, Shift As Integer)事件里分布用
- 问题问题问题,这个问题吗?分不多,但必给,求教了!
- 关于图书管理系统
- 如何从资源文件直接播放WAV文件
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
'-------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim wScreen As Long
Dim hScreen As Long
Dim w As Long
Dim h As Long
Dim pic As PictureBox
Picture1.Cls
Picture1.AutoRedraw = True
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY
Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
hdcScreen = GetDC(0)
p = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
Picture1.RefreshEnd SubPrivate Sub Command2_Click()
SavePicture Picture1.Image, "c:\111.bmp"
End Sub
都可以保存啊!
除非你的picture那个参数是空的!但正常情况下,PICTURE1。PICTURE只要获得对象就不可能为空啊!