C#全屏截图的方法 //得到屏幕的DC IntPtr dc1 = g1.GetHdc();这个得到的是你窗体的GC吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //得到屏幕的DC IntPtr dc1 = g1.GetHdc();屏幕的是IntPtr dc1 = GetDC(0);GetDC是windowsAPI,Intptr GetDC(IntPtr hwnd); 运行结果 是什么图都没有,为什么呢!!!?????using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;//using DWORD = System.UInt32;//using HANDLE = System.IntPtr;//using HDC = System.IntPtr;namespace SmartDeviceProject3{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")] private static extern bool BitBlt( IntPtr hdcDest, // 目标 DC的句柄 int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, // 源DC的句柄 int nXSrc, int nYSrc, System.Int32 dwRop // 光栅的处理数值 ); //[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")] //public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")] private static extern IntPtr GetCapture(); [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")] private static extern IntPtr GetDC(IntPtr hWnd); private void button1_Click(object sender, EventArgs e) { //IntPtr hwnd1 = FindWindow(null, "Form1"); this.Capture = true; IntPtr hwnd1 = GetCapture(); this.Capture = false; IntPtr hDC = GetDC(hwnd1); Graphics g1 = Graphics.FromHdc(hDC); //创建一个以当前屏幕为模板的图象 //Graphics g1 = Graphics.FromHdc(hwnd2); //创建以屏幕大小为标准的位图 Image bitmap = new Bitmap(800, 600); Graphics g2 = Graphics.FromImage(bitmap); //得到屏幕的DC IntPtr dc1 = g1.GetHdc(); //得到Bitmap的DC IntPtr dc2 = g2.GetHdc(); //调用此API函数,实现屏幕捕获 BitBlt(dc2, 0, 0, 800, 600, dc1, 0, 0, 13369376); //把当前屏幕拷贝到位图中 pictureBox1.Image = bitmap; //g1.ReleaseHdc(dc1); //释放屏幕句柄 g2.ReleaseHdc(dc2); } }} ListItem的Text和Value 水晶报表 记录号的问题 [求助]C# Winform中Form1和UserControl1之间怎么传值? 求高手帮忙类化个c#的语句 绑定数据的问题! 急:vs.net 2005 有对应的 tabtrip和MultiPage 控件么? 数组遍历 datagrid打印 请问:如何将visual c#.net的应用程序发布到没有安装.net Framework的系统上? .net 下如何引用华为的SMEIDll.dll? 怎么调整devexpress.xtragrid.gridcontrol列的宽度 问个nmodbus的问题
IntPtr dc1 = g1.GetHdc();屏幕的是IntPtr dc1 = GetDC(0);
GetDC是windowsAPI,Intptr GetDC(IntPtr hwnd);
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//using DWORD = System.UInt32;
//using HANDLE = System.IntPtr;
//using HDC = System.IntPtr;
namespace SmartDeviceProject3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // 目标 DC的句柄
int nXDest,
int nYDest,
int nWidth,
int nHeight,
IntPtr hdcSrc, // 源DC的句柄
int nXSrc,
int nYSrc,
System.Int32 dwRop // 光栅的处理数值
);
//[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
//public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
private static extern IntPtr GetCapture();
[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);
private void button1_Click(object sender, EventArgs e)
{
//IntPtr hwnd1 = FindWindow(null, "Form1"); this.Capture = true;
IntPtr hwnd1 = GetCapture();
this.Capture = false; IntPtr hDC = GetDC(hwnd1);
Graphics g1 = Graphics.FromHdc(hDC); //创建一个以当前屏幕为模板的图象
//Graphics g1 = Graphics.FromHdc(hwnd2);
//创建以屏幕大小为标准的位图
Image bitmap = new Bitmap(800, 600);
Graphics g2 = Graphics.FromImage(bitmap);
//得到屏幕的DC
IntPtr dc1 = g1.GetHdc();
//得到Bitmap的DC
IntPtr dc2 = g2.GetHdc();
//调用此API函数,实现屏幕捕获
BitBlt(dc2, 0, 0, 800, 600, dc1, 0, 0, 13369376); //把当前屏幕拷贝到位图中
pictureBox1.Image = bitmap;
//g1.ReleaseHdc(dc1); //释放屏幕句柄 g2.ReleaseHdc(dc2);
}
}
}