大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net获取屏幕截图 获取屏幕截图的两种方法

VB截取屏幕

[DllImport("user32.dll", EntryPoint = "GetDC")]

成都创新互联公司专注于冷水江企业网站建设,响应式网站开发,商城建设。冷水江网站建设公司,为冷水江等地区提供建站服务。全流程定制网站,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

public static extern IntPtr GetDC(IntPtr hWnd);

[DllImport("user32.dll", EntryPoint = "ReleaseDC")]

public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);

[DllImport("user32.dll", SetLastError = true)]

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", SetLastError = true)]

static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

先找到你要截图的那个窗体的 句柄 然后根据这个句柄得到改窗体的DC 创建一个bitmap 然后填充 得到的bitmap后 显示到picturebox里面

vb 如何获取当前窗口的一部分截图

'以下代码放模块,否则必须适当修改函数权限

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

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Type POINTAPI

X As Long

Y As Long

End Type

Public pt1 As POINTAPI, pt2 As POINTAPI

Public pt As POINTAPI

'函数提供指定区域截图,置入剪切板

Public Sub ScrnCap(Lt As Long, top As Long, Rt As Long, Bot As Long)

Dim rWidth, rHeight, SourceDC, DestDC, BHandle, Wnd, DHandle

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

'**********************************************************************************

'以下代码应该放窗体,单击执行

Private Sub Form_Click()

Dim Image1 As Object

Set Image1 = Controls.Add("VB.Image", "Image1") '添加控件用于显示

Image1.Visible = True: Image1.BorderStyle = 1 '样式

pt1.X = 100 / Screen.TwipsPerPixelX '单位转换

pt1.Y = 100 / Screen.TwipsPerPixelY

pt2.X = 1200 / Screen.TwipsPerPixelX

pt2.Y = 1200 / Screen.TwipsPerPixelY

ClientToScreen Me.hwnd, pt1 '转屏幕坐标

ClientToScreen Me.hwnd, pt2

Call ScrnCap(pt1.X, pt1.Y, pt2.X, pt2.Y) '调用函数,参数为左上,右下坐标

Image1.Picture = Clipboard.GetData() '图像显示

On Error Resume Next

Sleep 500

SavePicture Clipboard.GetData, "C:\图片1.bmp" '保存图像

End Sub

’测试通过,

'注:自定义函数ScrnCap()是核心截图函数,Form_Click()里有窗口坐标客户区转屏幕的实例代码,很明了,一看就懂

vb.net 截屏 ,获取活动窗口

'模块中

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等,使用“粘贴”命令即可使用

请问:在vb.net2015中,如何编写截图程序?

Me.Refresh()

Dim memory As Image = New Bitmap(Me.Width, Me.Height)

Dim g As Graphics = Graphics.FromImage(memory)

g.CopyFromScreen(Me.Left, Me.Top, 0, 0, New Size(Me.Width, Me.Height)) '这里是截屏核心代码

Dim FilePath As String = ""

Dim d As New SaveFileDialog

d.Filter = "JPEG图像|*.JPEG"

If d.ShowDialog = Windows.Forms.DialogResult.OK Then

FilePath = d.FileName

If FilePath = "" Then Exit Sub

'If FilePath.Substring(FilePath.Length - 1, 1)  "\" Then FilePath = FilePath  "\"

Else

Exit Sub

End If

d.Dispose()

memory.Save(FilePath)

MessageBox.Show("图像已经保存到: "  FilePath, "截图成功", MessageBoxButtons.OK, MessageBoxIcon.Information)

vb.net 2008 如何将指定的窗体截图并保存

INTOUCH自带的就有,打印屏幕的命令

自己写个时间条件运行那命令就可以了

PRINTSCREEN这个命令 具体怎么用 看下帮助

希望我的回答对你有所帮助

如有其他问题,可以继续追问,您的采纳是我前进的动力!


网站名称:vb.net获取屏幕截图 获取屏幕截图的两种方法
网址分享:http://dzwzjz.com/article/doccgcs.html
在线咨询
服务热线
服务热线:028-86922220
TOP