博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# Get Desktop Screenshot ZZ
阅读量:6003 次
发布时间:2019-06-20

本文共 831 字,大约阅读时间需要 2 分钟。

I found this feature while looking inside Graphics class and since it was so simple to use, I decided to post it here.

As I said, it doesn't require more than 15 lines of code - this function: Graphics.CopyFromScreen does all the 'hard work' so we only need to put this into a Bitmap and save/display it.

To the code!

There are 3 steps that you need to follow:

  • create a Bitmap that's exactly the screen's size
  • using that Bitmap, create a Graphics object (Graphics.FromImage)
  • use CopyFromScreen() and save the Bitmap

The code looks like this:

    1. private void takeScreenShot()
    2. {
    3. Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    4. using (Graphics g = Graphics.FromImage(bmp))
    5. {
    6. g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
    7. bmp.Save("screenshot.png"); // saves the image
    8. }
    9. }

转载地址:http://asbmx.baihongyu.com/

你可能感兴趣的文章
44. Ext信息提示对话框
查看>>
vue--1.环境搭建及创建项目
查看>>
Java中Final修饰一个变量时,是引用不能变还是引用的对象不能变
查看>>
Linq 查询示列
查看>>
垃圾收集器(一)
查看>>
JTAG 学习 -SVF格式
查看>>
1096:零起点学算法03——超简单模仿算术题
查看>>
lambda表达式中的排序问题
查看>>
如何提升自身实力
查看>>
lvm调整分区大小
查看>>
微信H5支付----报undened index openid
查看>>
网页图片裁剪插件
查看>>
Python 面向对象_继承、组合
查看>>
在bash shell中打开PDF
查看>>
[NOIP2017]逛公园
查看>>
[NOI2017]蔬菜——时光倒流+贪心
查看>>
查看进程
查看>>
Android Studio切换为eclipse的快捷键之后还是有区别的部分快捷键
查看>>
静态内部类(转)
查看>>
网络 协议 2
查看>>