標籤:系統 映像 prim sqli 建立 create mes dcs graphics
本文執行個體講述了c#映像截取的實現方法。分享給大家供大家參考。具體如下:
映像截取的相關代碼如下:
代碼如下:
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Image pic = new Bitmap(this.Width, this.Height);
Graphics graphic = Graphics.FromImage(pic);
graphic.CopyFromScreen(new Point(this.Location.X, this.Location.Y), new Point(0, 0), new Size(this.Width, this.Height));
pic.Save(@”d:/test.jpeg”, ImageFormat.Jpeg);
graphic.Dispose();
}
[System.Runtime.InteropServices.DllImportAttribute(“gdi32.dll”)]
private static extern bool BitBlt(
IntPtr hdcDest, //目標裝置的控制代碼
int nXDest, // 目標對象的左上方的X座標
int nYDest, // 目標對象的左上方的X座標
int nWidth, // 目標對象的矩形的寬度
int nHeight, // 目標對象的矩形的長度
IntPtr hdcSrc, // 源裝置的控制代碼
int nXSrc, // 來源物件的左上方的X座標
int nYSrc, // 來源物件的左上方的X座標
System.Int32 dwRop // 光柵的操作值
);
[System.Runtime.InteropServices.DllImportAttribute(“gdi32.dll”)]
private static extern IntPtr CreateDC(
string lpszDriver, // 驅動名稱
string lpszDevice, // 裝置名稱
string lpszOutput, // 無用,可以設定位”NULL”
IntPtr lpInitData // 任意的印表機資料
);
private void Form1_SizeChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
IntPtr dc1 = CreateDC(“DISPLAY”, null,
null, (IntPtr)null);
//建立顯示器的DC
Graphics g1 = Graphics.FromHdc(dc1);
//由一個指定裝置的控制代碼建立一個新的Graphics對象
Bitmap MyImage =
new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, g1);
//根據螢幕大小建立一個與之相同大小的Bitmap對象
Graphics g2 = Graphics.FromImage(MyImage);
//獲得螢幕的控制代碼
IntPtr dc3 = g1.GetHdc();
//獲得位元影像的控制代碼
IntPtr dc2 = g2.GetHdc();
//把當前螢幕捕獲到位元影像對象中
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
dc3, 0, 0, 13369376);
//把當前螢幕拷貝到位元影像中
g1.ReleaseHdc(dc3);
//釋放螢幕控制代碼
g2.ReleaseHdc(dc2);
//釋放位元影像控制代碼
Bitmap img = new Bitmap(MyImage, 800, 600);
//縮放圖片到800*600
img.Save(“d:\\MyJpeg.jpg”, ImageFormat.Jpeg);
MessageBox.Show(“已經把當前螢幕儲存到” +
“C:\\MyJpeg.jpg檔案中!”);
this.Show();
}
除聲明外,
跑步客文章均為原創,轉載請以連結形式標明本文地址
c#映像截取執行個體
本文地址: http://www.paobuke.com/develop/c-develop/pbk23433.html
相關內容C#產生漂亮驗證碼完整代碼類淺析C# 中的類型系統(實值型別和參考型別)c#幾種資料庫的大資料批量插入(SqlServer、Oracle、SQLite和MySql)C#畫筆Pen使用路徑繪製圖形的方法
C#畫筆Pen用法執行個體C#讀取目錄下所有指定類型檔案的方法C#函數式編程中的惰性求值詳解win7中C#的winForm編程使用savefiledialog不能彈出儲存表單的解決方案
c#映像截取執行個體