重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Declare Function icePub_copyForegroundFormToClipboard Lib "icePubDll.dll" () As Integer
创新互联是一家集网站建设,泗水企业网站建设,泗水品牌网站建设,网站定制,泗水网站建设报价,网络营销,网络优化,泗水网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
Dim a2 As Integer
a2 = icePub_copyForegroundFormToClipboard()
Private Declare Function icePub_saveClipboardToBmpFile Lib "icePubDll.dll" (ByVal strBmpFilename As String) As Integer
Dim a2 As Integer
a2 = icePub_saveClipboardToBmpFile("d:\c.bmp")
Private Declare Function icePub_saveScreen Lib "icePubDll.dll" (ByVal bmpFile As String) As Integer
Dim str1 As String
Dim a2 As Integer
str1 = App.Path + "\1.bmp"
a2 = icePub_saveScreen(str1)
VB.NT用的是触发事件,一按就会触发,要不你加个timer控件,延迟一秒
标题的问题:你先把图片保存,再加载
按快捷键后,先把整个屏幕截下来,然后显示在form1上,form1是一个没有边框的窗体,之后最大化显示form1,开始鼠标拖坐标,截取坐标内的图片,保存,
补充:
4年前用vb写的:
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const theScreen = 0
Const theForm = 1
Private Sub Form_Load()
XPForm1.Make
Load Form2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
Unload Me
End Sub
Private Sub HScroll1_Change()
If Picture1.Width Picture2.Width Then
Picture1.Left = -((Picture1.Width - Picture2.Width) / 100) * HScroll1.Value
End If
End Sub
Private Sub MGButton1_Click()
If Option1.Value = True Then
If Check1.Value = 1 Then
Me.Hide
End If
Call Delay
Call keybd_event(vbKeySnapshot, theScreen, 0, 0)
Call Delay
Form2.Picture = Clipboard.GetData(vbCFBitmap)
Form2.Shape1.Height = 0
Form2.Shape1.Width = 0
Form2.Picture2.Visible = False
Form2.Picture3.Visible = False
Form2.Picture4.Visible = False
Form2.Show 1, Me
ElseIf Option2.Value = True Then
If Check1.Value = 1 Then
Me.Hide
End If
Call Delay
Call keybd_event(vbKeySnapshot, theScreen, 0, 0)
Call Delay
Picture1.Cls
Picture1.Picture = Clipboard.GetData(vbCFBitmap)
Me.Show
ElseIf Option3.Value = True Then
If Check1.Value = 1 Then
Me.Hide
End If
Call Delay
Call keybd_event(vbKeySnapshot, theForm, 0, 0)
Call Delay
Picture1.Cls
Picture1.Picture = Clipboard.GetData(vbCFBitmap)
Me.Show
Else
End If
End Sub
Private Sub Delay()
Dim i As Integer
For i = 0 To 1000
DoEvents
Next i
End Sub
Private Sub MGButton2_Click()
Picture1.Cls
Picture1.Picture = LoadPicture
End Sub
Private Sub MGButton3_Click()
CommonDialog1.DialogTitle = "保存"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "位图文件(*.BMP)|*.bmp|所有文件(*.*)|*.*"
CommonDialog1.FilterIndex = 0
CommonDialog1.ShowSave
If CommonDialog1.FileName "" Then
SavePicture Picture1.Image, CommonDialog1.FileName
End If
End Sub
Private Sub MGButton4_Click()
Clipboard.SetData Picture1.Image, vbCFBitmap
End Sub
Private Sub VScroll1_Change()
If Picture1.Height Picture2.Height Then
Picture1.Top = -((Picture1.Height - Picture2.Height) / 100) * VScroll1.Value
End If
End Sub
下面的代码是我很欣赏的编程牛人CBM666的,你看下就应该能明白意思了,需要的haunted自己修改一下,我运行过了可以运行成功,不会截到其它窗体只是打印当前窗体
友情提示:你点下打印键的时候没有提示会直接打印出窗口内容来,没有确定取消的按钮的,当初我在公司试的时候随便贴了个很烂的图就给打出来了,还被人笑了。。。
'添加 Picture1 Picture2 各别放一张图片 窗体也可加图片, 只是测试用罢了.
,Text1 随便打一些内容,(只是测试用)
'再随便加一个Picture3 用来保存图片
'Command1 抓图存图 Command2 打印
'本代码是将窗体内所有的控件与窗体一起保存到Picture3再打印出来.
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const theScreen = 0 '整个Screen
Const theForm = 1 '当前活动界面
Private Sub Form_Load()
Command1.Caption = "抓取窗体"
Command2.Caption = "打 印"
Picture3.Move Screen.Width
Picture3.AutoRedraw = True
Picture3.BorderStyle = 0
Me.AutoRedraw = False
Clipboard.Clear
End Sub
Private Sub Command1_Click()
Me.Refresh
Picture3.Picture = LoadPicture()
Picture3.Width = Me.Width
Picture3.Height = Me.Height
Call keybd_event(vbKeySnapshot, 1, 0, 0)
DoEvents
Picture3.Picture = Clipboard.GetData(vbCFBitmap)
Set Picture3.Picture = Picture3.Image '此时才真正显示Picture
'SavePicture Picture3.Image, "c:\kkkw.bmp"
End Sub
Private Sub Command2_Click()
Printer.PaintPicture Picture3.Picture, 0, 0, Picture3.Width, Picture3.Height
Printer.EndDoc
End Sub
有空你搜索下CBM666的代码,绝对能给你很大收获
'模块中
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) _
As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
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
'form1中
Private Sub Command1_Click()
Dim hDCtmp As Long, picWidth As Double, picHeight As Double
Dim x As Double
Dim y As Double
x = Val(Text2.Text)
y = Val(Text3.Text)
picWidth = Val(Text3.Text)
picHeight = Val(Text4.Text)
hDCtmp = GetDC(0)
BitBlt Picture1.hdc, 0, 0, picWidth, picHeight, hDCtmp, x, y, vbSrcCopy
ReleaseDC 0, hDCtmp
End Sub
目的: 将屏幕按照指定坐标和大小进行截取成图,在picture1显示
问题: 大小是相同了,为什么截取的坐标不对,只是屏幕上的左上
相信大家都用过QQ截图功能。不过很多人并没有真正掌握好它的用法。将QQ截图与其它截屏和制图软件配合使用,会有意想不到的效果。
获取颜色的RGB值
我们在编辑图片或网页的时候,经常需要获取某种颜色的“RGB值”,所以很多人都安装了第三方的颜色吸取工具。其时用QQ截图键即可获取屏幕上任意颜色的RGB值。
当按下“Ctrl+Shift+A”弹出“截图”提示框时,提示框中的“当前像素RGB”即为当前鼠标屏幕位置的颜色RGB值,将鼠标移动到你想查看的屏幕颜色上即可获得相应的RGB值(如图1)。
图1精确截取图片大小
有时我们对要使用的截图尺寸有严格要求,比如论坛签名或QQ头像等。用QQ截图键可以按尺寸精确截取,一步到位无需再进行后期裁剪了。
按下QQ截图键,按住鼠标不放选取截取范围时,在鼠标上方会有一个信息框显示当前范围的详细信息,其中“矩形大小”就是以像素来表示的图片的尺寸大小,括号内的数字分别表示的是长和高(如图2)。松开鼠标调整截图框时,对照“矩形大小”就可以按需要的尺寸来精确截图范围,然后用鼠标点住截图框将截图框拖到要截取的图片上,双击即可获得所需尺寸的图片了。
图2图片拼贴好帮手
大部分的截图软件一次只能截取一张图片,当要截取多张图片并进行拼贴组合时,就需要一张一张截取全部保存后再进行拼贴操作,非常麻烦。
我们知道用QQ截图键截取的图片可以在任一个可以粘贴图片的程序中使用,这样只需用截图软件进行一次截图操作,剩下的图片用QQ截图键来截取,然后依次粘贴到截图软件的窗口中即可快速进行拼贴操作了,是不是很方便啊。
小提示:QQ截图键无需打开聊天窗口即可使用,截取的图片在任一可粘贴图片的程序窗口中如画图、Word等,使用“粘贴”命令即可使用
1. 启动新 VisualBasic 常用 Exe 项目。 默认情况下创建 Form 1。
2. 在 项目 菜单上, 选择将一个新模块添加到现有项目 添加模块 。
3. 向窗体, 名称之一添加两 图片框 Pic_Edit (目标), 和其他名称 Pic_Dest (目标)。
4. 将是 Pic_Edit Picture 属性设置为要从中选择区域位图
5. 将是 Pic_Dest AutoRedraw 属性设置为 True
6. 以下代码添加到 Module 1:Public Const INVERSE = 6
Public Const DOT = 2
Public Const SOLID = 0
Public OrigX As Long
Public OrigY As Long
Public DestX As Long
Public DestY As Long
Public Sub Draw_Selection_Rectangle()
' Set drawing mode to INVERSE since this routine also used to erase
' the selection rectangle by simply drawing over the currently
' displayed rectangle
With Editor.Pic_Edit
.DrawMode = INVERSE
.DrawStyle = DOT
Editor.Pic_Edit.Line (OrigX, OrigY)-(DestX, DestY), , B
.DrawStyle = SOLID
End With
End Sub
Public Sub Copy_Rectangle()
With Editor.Pic_Dest
.Cls
.Visible = True
.Height = DestY - OrigY
.Width = DestX - OrigX
.PaintPicture Editor.Pic_Edit, 0, 0, (DestX - OrigX), _
(DestY - OrigY), OrigX, OrigY, (DestX - OrigX), _
(DestY - OrigY), vbSrcCopy
End With
' Make sure the clipboard is clear, then copy the image:
Clipboard.Clear
Clipboard.SetData Editor.Pic_Dest.Image
End Sub
7. 以下代码添加到 Form 1:Private Sub Pic_Edit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Pic_Edit.Refresh
Pic_Dest.Visible = False
OrigX = X
OrigY = Y
DestX = OrigX
DestY = OrigY
Call Module1.Draw_Selection_Rectangle
End Sub
Private Sub Pic_Edit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
DestX = X
DestY = Y
Pic_Edit.Refresh
Call Module1.Draw_Selection_Rectangle
End If
End Sub
Private Sub Pic_Edit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Check to see if mouse moved or goes the "wrong" way:
If DestX = OrigX Or DestY = OrigY Then
Pic_Edit.Refresh
Exit Sub
End If
If Button = 1 Then Call Copy_Rectangle
End Sub
8. 启动应用程序并选择用鼠标与位图的区域。 当您松开鼠标按钮, Pic_Dest 出现 备注 所选区域: 如果备份 MS 画图、 MSWord 或任何其他应用程序可能需要粘贴位图, 打开您就可以粘贴到该应用程序图像的选定部分。 也可以通过剪贴板查看程序查看剪贴板的内容。