初学: 如何截取屏幕上某一区域的图象?

FranklinBHU 教师  2003-12-18 05:05:13
例如:截取屏幕上左上角坐标为(100,150),大小为(200*250)的图象,并保存。
如何用程序实现?
...全文
124 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-12-18
savepicture picture1.image,"c:\temp.bmp"
回复
rainstormmaster 2003-12-18
至于保存,可以这样:

savepicyure picture1.image,"c:\temp.bmp"

picturebox的autoredraw属性要设置为true
回复
rainstormmaster 2003-12-18
先全部截取,再BitBlt得到指定区域的图象
回复
海牛 2003-12-18
可以更简单啊!!!
在窗体添加一个PictureBox

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 Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub CopyScreen(objPicBox As PictureBox, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long)
objPicBox.AutoRedraw = True
BitBlt objPicBox.hDC, 0, 0, Width, Height, GetDC(0), X, Y, vbSrcCopy
objPicBox.Refresh
End Sub

Private Sub Form_Load()
Call CopyScreen(Me.Picture1, 100, 100, 300, 300)
End Sub

回复
liyan010 2003-12-18
学习 & 保存
回复
SoHo_Andy 2003-12-18
'捕捉屏幕图象VB源代码

'api函数声明:
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
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 Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long

'函数:
Sub ScrnCap(Lt, Top, Rt, Bot)
rWidth = Rt - Lt
rHeight = Bot - Top
SourceDC = CreateDC("DISPLAY", 0, 0, 0)
DestDC = CreateCompatibleDC(SourceDC)
BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
SelectObject DestDC, BHandle
BitBlt DestDC, 0, 0, rWidth, rHeight, SourceDC, Lt, Top, &HCC0020
Wnd = Screen.ActiveForm.hwnd
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, BHandle
CloseClipboard
DeleteDC DestDC
ReleaseDC DHandle, SourceDC
End Sub

'以下的示例把屏幕图象捕捉后,放到Picture1 中。
Sub Command1_Click()
Form1.Visible = False
ScrnCap 100, 150, 200, 250
Form1.Visible = True
Picture1 = Clipboard.GetData()
End Sub

完全搞定,结贴
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告