• C# 截屏方式


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Imaging;
    
    namespace zhuaScreen
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern bool BitBlt(
             IntPtr hdcDest,                  //目的DC的句柄 
             int nXDest,                        //目的图形的左上角的x坐标 
             int nYDest,                        //目的图形的左上角的y坐标 
             int nWidth,                         //目的图形的矩形宽度 
             int nHeight,                        //目的图形的矩形高度 
             IntPtr hdcSrc,                    //源DC的句柄 
             int nXSrc,                          //源图形的左上角的x坐标 
             int nYSrc,                           //源图形的左上角的x坐标 
             System.Int32 dwRop          //光栅操作代码 
             ); 
            private void button1_Click(object sender, EventArgs e)
            {
                Graphics g1 = this.CreateGraphics();                                                                                      //获得窗体图形对象 
                Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
                Graphics g2 = Graphics.FromImage(MyImage);                                                                      //创建位图图形对象 
                IntPtr dc1 = g1.GetHdc();                                                                                                         //获得窗体的上下文设备 
                IntPtr dc2 = g2.GetHdc();                                                                                                           //获得位图文件的上下文设备 
                BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);//写入到位图 
                g1.ReleaseHdc(dc1);                                                                                                                  //释放窗体的上下文设备 
                g2.ReleaseHdc(dc2);                                                                                                                 //释放位图文件的上下文设备 
                MyImage.Save("Captured.jpg", ImageFormat.Jpeg);                                                                //保存为jpeg文件 
                MessageBox.Show("保存图片在同目录下结束!"); 
            }
        }
    }
  • 相关阅读:
    61. 最长不含重复字符的子字符串
    60. 礼物的最大价值 (未理解)
    59. 把数字翻译成字符串
    58. 把数组排成最小的数
    57. 数字序列中某一位的数字 (不懂)
    spring data jpa 官方文档
    idea 编译报错 源发行版 1.8 需要目标发行版 1.8
    idea maven 依赖报错 invalid classes root
    solr
    spring boot 官方文档
  • 原文地址:https://www.cnblogs.com/flyhigh1860/p/2548605.html
Copyright © 2020-2023  润新知