找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2654|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

C#實(shí)現(xiàn)全屏截圖

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:83710 發(fā)表于 2015-6-25 16:50 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
C#實(shí)現(xiàn)全屏截圖,雖然沒(méi)有什么大用吧、但還是記錄下吧!

    直接代碼、沒(méi)什么好解釋的:

    
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Threading;

    namespace Screenshot
    {
        class Program
        {
            public static int width = 0;   // 截圖的寬
            public static int height = 0;  // 截圖的高

            static void Main(string[] args)
            {
                Console.WriteLine("3秒后開(kāi)始全屏截圖!");
                Thread.Sleep(3000); // 當(dāng)前線程休眠3S
                width = Screen.PrimaryScreen.Bounds.Width;  // 獲取系統(tǒng)寬
                height = Screen.PrimaryScreen.Bounds.Height;    // 獲取系統(tǒng)高
                string strFile = "C:\\" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".jpg";    // 文件保存的路徑
                ScreenShow(strFile, width, height); 
                Console.WriteLine("提示:截圖保存為" + strFile);
                Console.ReadKey();  // 等待用戶(hù)輸入退出
            }


            /// <summary>
            /// 全屏截圖
            /// </summary>
            /// <param name="strFileName">保存路徑</param>
            /// <param name="nWidth">圖片寬</param>
            /// <param name="nHeight">圖片高</param>
            /// <returns></returns>
            public static Bitmap ScreenShow(string strFileName, int nWidth, int nHeight)
            {
                Bitmap btm = new Bitmap(nWidth, nHeight);   // 新建一個(gè)Bitmap對(duì)象
                using (Graphics g = Graphics.FromImage(btm))
                {
                   g.CopyFromScreen(0, 0, 0, 0, Screen.AllScreens[0].Bounds.Size); // 獲取第0個(gè)顯示器的大小
                    g.Dispose();
                    btm.Save(strFileName, ImageFormat.Jpeg);    // 保存
                }
                return btm;
            }
        }
    }
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表