用VB6.0实现,本人vb比较菜,所以最好是完整代码,也希望能附上注释,在这里多谢了~
问题补充:
借助外部工具比较简单,我想用代码实现 ,希望高手帮一下,非常感谢!!
辛语辛辰 ,savepicture可以保存图片,不过我想保存时主窗体中的一部分,并且上面可能有控件,不知道还有什么方法吗?
最佳答案
Dim t As Boolean
Dim f As Boolean
Private Sub Form_Load()
Pic.Height = 100
Pic.Width = 100
Pic.AutoRedraw = True
End Sub
Private Sub Pic0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If t = False Then
Pic.Left = X
Pic.Top = Y
End If
If Button = 1 And f = False Then
t = True
Pic.Width = X - Pic.Left
mousemove是什么键 Pic.Height = Y - Pic.Top
Pic.PaintPicture Pic0.Picture, 0, 0, , , Pic.Left, Pic.Top, Pic.Width, Pic.Height
End If
End Sub
Private Sub Pic0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then f = True
Pic2.Picture = Pic.Image
If Button = 2 Then
t = False
f = False
Pic.Width = 100
Pic.Height = 100
End If
End Sub
注释不用了吧,用SavePicture 语句保存图片
说详细点,它截取的是背景
vb 屏幕区域截图
悬赏分:0 | 解决时间:2008-3-8 19:24 | 提问者:開始習慣孤單
例如我要截下屏幕上728,292,766,305处的图并保存,怎样写代码
代码越短越好
最佳答案
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 Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Const Srccopy = &HCC0020
Private Sub Picture1_Click()
StretchBlt Picture1.hdc, 0, 0, 766 - 728, 305 - 292, GetDC(0), 728, 292, 766 - 728, 305 - 292,Srccopy
'自己写保存图片的过程吧~
End Sub
PictureBox的ScaleMode要设置为pixel.
你试试这个行不~
PS 这个问题我好像见过 ?_?
通过VB的BitBlt API来实现 窗口局部区域截图
悬赏分:150 | 解决时间:2010-10-21 22:52 | 提问者:诚信欢迎你
我想将这个代码写成一个函数形式,保存为DLL文件
自己用SavePicture方法可以保存图片但是,保存为DLL的时候报错说未定义什么
我想各位帮忙想想通过什么方法能保存为图片
问题补充:
此问题通过交换方法已经解决了,3楼给的方法就是我说的那方法不过用到了插件
故无法生成DLL吧,不过还是非常感谢
最佳答案
这个问题我以前也弄过,后来卡在你这个问题同样的地方没弄下去,现在看到你的问题,很有感触,准备再弄一下看看,没想到成功了哈,下面是代码,实现了后台截图并且保存,可以用到一些游戏脚本里面哈。
首席准备2个Picture窗口和一个按钮,然后就是下面的代码,有问题请补充问题,我们交流哈哈
Option Explicit
Private Declare Function PrintWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcBlt As Long, ByVal nFlags 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 Sub Command1_Click()
Dim a
a = PrintWindow(395116, Picture1.hDC, 0)
BitBlt Picture2.hDC, 0, 0, 300, 300, Picture1.hDC, 0, 0, vbSrcCopy
SavePicture Picture2.Image, "c:\aaa.bmp"
End Sub
注意,2个Picture窗口的AutoRedraw属性必须设置成真
第一个Picture后台获取整张图片,第二个用来获取需要的大小
模拟QQ截屏效果。 收藏
QQ确实太占资源了, 物理内存和虚拟内存加起来大概有40多M,不过他提供的屏幕截图功能却是不错,能方便的选取能所感兴趣的区域图片,本文试图用VB模拟这一功能,当
然功能还是要比QQ截屏少一点,但基本的功能以完备。
截屏原理:QQ截屏应该时先把当前屏幕的内容拷贝到一个窗体,并且这个窗体和屏幕一样大,然后再对这个窗体上的图片进行处理,因此在使用QQ截屏的时候你会发现托盘区那个网络链接的图标不会有变换,把鼠标放在时间上也不会有日期提示了。
知道了原理,用VB来实现也不时一件难事了。
窗体及倥件设置:一个picturebox,picture属性设置为你自己想要的图片(既然模仿QQ,就用他截屏时出现再屏幕顶部那个图片吧),其上有几个label倥件数组(lblInfo(0~4)),用来显示提示信息的。一个Timer倥件,interal设置为20,用来模拟QQ截屏时提示图片的下拉效果。一个shape倥件,形状为矩形,边框样式为虚线点装。设置窗体的borderstyle为无边框的,showintaskbar属性为true(一定要为True).,keypreview属性为true.
下面是代码:
'程序实现功能:模拟QQ截屏
'作 者: laviewpbt
': laviewpbt@sina
'QQ:33184777
'版本:Version 1.0.0
'说明:复制请保留源作者信息,转载请说明,欢迎大家提出意见和建议
Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y 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 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 GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, ByVal Cy As Long, ByVal wFlags As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论