Imports System.Runtime.InteropServices Imports System.Drawing.Imaging Public Class Form1 Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Int32) As Int32 Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer Private picture As Bitmap = Nothing '以picture作为图片格式的声 Public Sub capture_window() Dim capture1 As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, Nothing) Dim get1 As Graphics = Graphics.FromHdc(capture1) '创建一个新的Graphics对象 picture = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, get1) '根据屏幕大小创建一个相同大小的Bitmap Dim get2 As Graphics = Graphics.FromImage(picture) Dim get3 As IntPtr = get1.GetHdc() '获取屏幕的句柄 Dim get4 As IntPtr = get2.GetHdc() '获取位图的句柄 BitBlt(get4, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, get3, _ 0, 0, 13369376) '把当前屏幕复制到位图中 get1.ReleaseHdc(get3) '释放屏幕句柄 get2.ReleaseHdc(get4) '释放位图句柄 picture.Save("CapturePicture.jpg", ImageFormat.Jpeg) MessageBox.Show(" 已经把当前截取屏幕保存到CapturePicture.jpg,检查程序根目录") Me.Visible = True End Sub'vb.net代码 你转下就可以了
Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds; Image img = new Bitmap(R.Width, R.Height); Graphics G = Graphics.FromImage(img); G.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(R.Width, R.Height));。 IntPtr dc = G.GetHdc(); G.ReleaseHdc(dc); G.Dispose(); img .Save("c:\\a.jpg"); 或 private static extern bool BitBlt(IntPtr hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,int nXSrc,int nYSrc,Int32 dwrop);http://topic.csdn.net/u/20090911/14/5614A16E-AB08-4106-901E-E8DCC5CD1FA3.html
看这个 仿QQ截图 网上很多
http://www.002pc.com/master/College/Language/C/2008-11-27/4655.html
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Public Class Form1
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Int32) As Int32
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Private picture As Bitmap = Nothing '以picture作为图片格式的声 Public Sub capture_window() Dim capture1 As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, Nothing)
Dim get1 As Graphics = Graphics.FromHdc(capture1)
'创建一个新的Graphics对象
picture = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, get1)
'根据屏幕大小创建一个相同大小的Bitmap
Dim get2 As Graphics = Graphics.FromImage(picture)
Dim get3 As IntPtr = get1.GetHdc() '获取屏幕的句柄
Dim get4 As IntPtr = get2.GetHdc() '获取位图的句柄
BitBlt(get4, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, get3, _
0, 0, 13369376) '把当前屏幕复制到位图中
get1.ReleaseHdc(get3) '释放屏幕句柄
get2.ReleaseHdc(get4) '释放位图句柄
picture.Save("CapturePicture.jpg", ImageFormat.Jpeg)
MessageBox.Show(" 已经把当前截取屏幕保存到CapturePicture.jpg,检查程序根目录")
Me.Visible = True
End Sub'vb.net代码 你转下就可以了
Image img = new Bitmap(R.Width, R.Height);
Graphics G = Graphics.FromImage(img);
G.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(R.Width, R.Height));。
IntPtr dc = G.GetHdc();
G.ReleaseHdc(dc);
G.Dispose();
img .Save("c:\\a.jpg");
或
private static extern bool BitBlt(IntPtr hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,int nXSrc,int nYSrc,Int32 dwrop);http://topic.csdn.net/u/20090911/14/5614A16E-AB08-4106-901E-E8DCC5CD1FA3.html