首页 > 编程语言 >C#实现截屏功能

C#实现截屏功能

时间:2024-05-09 11:24:41浏览次数:14  
标签:功能 bounds C# System Bitmap bmp 截屏 using Empty

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

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Bitmap bitmap = CaptureActiveScreen();
bitmap.Save("screenshot.png", ImageFormat.Png);
}

public Bitmap CaptureActiveScreen()
{
// 创建一个和当前屏幕一样大小的Bitmap
Rectangle bounds = Screen.GetBounds(Point.Empty);
Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);

// 创建一个画布
Graphics g = Graphics.FromImage(bmp);

// 截取整个屏幕
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);

// 释放画布资源
g.Dispose();

return bmp;
}
}
}

标签:功能,bounds,C#,System,Bitmap,bmp,截屏,using,Empty
From: https://www.cnblogs.com/huanglg/p/18181713

相关文章

  • Java-读取resource目录下的文件并返回给前端
    我在项目的resource目录下面放了一个模板文件,用来供用户下载提供一个接口给前端,用来下载在Utils类下面写个方法来读取代码publicstaticvoidgetXMindTemplate(HttpServletResponseresponse){StringfileName="templates/TestCaseTemplate.xmind";//文件名称ClassPa......
  • Mysql替换字段中指定字符(replace 函数)
    一、简介函数将字符串中出现的所有子字符串替换为新的子字符串。REPLACE()函数是基于字符的替换,并且替换字符串时是区分大小写的。二、语法这里是MySQLREPLACE()函数的语法:REPLACE(str,from_str,to_str)参数str必需的。原字符串。from_str必需的。被替换的子字符......
  • 微信小程序使用微信云托管添加自定义域名并转发到pexels.com
    背景:我要在小程序上显示pexels.com上的图片,然后我得先把pexels.com的域名添加到小程序的request合法域名中,但是pexels.com是国外的,在国内没有备案所以添加不了。解决方案就是:用一个已经备案好的域名进行转发,转发的服务器我选择的是微信云托管,备案好的域名还需要ssl,没有的话本文会......
  • Java-LocalDateTime时间和时间(时间加减)
    前言一开始使用Date类来表述时间属性一个问题是时间戳的问题,另一个问题是读取Excel数据格式的时候没有那么灵活 1.基本知识LocalDateTime是Java8引入的日期和时间API中的一个类,位于java.time包中。它提供了一种更灵活、更方便的方式来处理日期和时间,相比旧的Date类更为......
  • idea使用svn报错-Error:Can not get current revision for file
    idea中使用svn结果报错:Error:CannotgetcurrentrevisionforfileD:/IDEADire…,并且idea提示一下警告:解决方案:安装svn的时候要主要勾选上第二个选项,如下图所示:最后在idea中配置svn的安装路径下的svn.exe,File->settings->VersionControl–>Subversion......
  • configure,make和make install关系
    一.参考网址1. configure、make、makeinstall背后的原理(翻译)2. configure,make和makeinstall关系3. Linux:configuremake、makeinstall ......
  • 易基因:cfDNA甲基化组多模式分析早期检测食管鳞状细胞癌和癌前病变|Nature子刊
    大家好,这里是专注表观组学十余年,领跑多组学科研服务的易基因。食管癌(EC)是最常见的胃肠道恶性肿瘤之一,食管鳞状细胞癌(ESCC)是EC的主要组织学亚型,约占新EC病例的88%,大多数发生在东亚和中亚。与晚期ESCC的预后极差相比,早期ESCC(如黏膜内ESCC)和前体病变(如上皮内瘤变,IEN)可以通过内镜下整......
  • 中英文自动化 vve-i18n-cli
    安装npminstallvve-i18n-cli-Dpackage里添加脚本命令,简化命令使用{"scripts":{"i18n":"vve-i18n-cli","i18n-wrap":"vve-i18n-zh-wrap-cli","i18n-check":"vve-i18n-zh-check-cli"}......
  • rockylinux9.2 配置本地镜像源
    创建目录,挂载iso镜像mkdir/media/isomount/dev/cdrom/media/iso备份源cd/etc/yum.repos.dcprocky.reporocky.repo.bakcprocky-extras.reporocky-extras.repo.bak创建镜像源catmedia/iso/media.repo>/etc/yum.repos.d/media.repo编辑镜像源[Insta......
  • LeetCode 2210. Count Hills and Valleys in an Array
    原题链接在这里:https://leetcode.com/problems/count-hills-and-valleys-in-an-array/description/题目:Youaregivena 0-indexed integerarray nums.Anindex i ispartofa hill in nums iftheclosestnon-equalneighborsof i aresmallerthan nums[i].......