C#实现截屏功能

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;
}
}
}

posted @   huanglg  阅读(313)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示