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

C# Get Desktop Screenshot ZZ的更多相关文章

  1. Pyqt 屏幕截图工具

    从Pyqt的examples中看到一段截图代码, (路径:examplas\desktop\screenshot.py) 所以想自己UI下界面,手动练习下 通过UI生成的: Screenshot.py ...

  2. java 图片处理

    /* * 图片处理类 */ package image; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.j ...

  3. 编译x11版本qt

    用buildroot 选择x11相关 在选择qt x11版本   export PATH=~/buildroot/output/host/usr/bin:$PATH 进入~/buildroot/out ...

  4. 更改mac电脑图片默认存储位置

    1.创建存储位置screenshot 2.打开terminal 3.defaults write com.apple.screencapture location ~/Desktop/screensh ...

  5. 用IDesktopWallpaper接口设置png壁纸

    #include <Windows.h> #include <string> #include "Shobjidl.h" int main() { std: ...

  6. [ZZ] The Naked Truth About Anisotropic Filtering

    http://www.extremetech.com/computing/51994-the-naked-truth-about-anisotropic-filtering In the seemin ...

  7. Running a Remote Desktop on a Windows Azure Linux VM (远程桌面到Windows Azure Linux )-摘自网络(试了,没成功 - -!)

                              A complete click-by-click, step-by-step video of this article is available ...

  8. ZZ:Solaris 10 软件包分析

    ZZ:Solaris 10 软件包分析 http://blog.chinaunix.net/uid-22759617-id-276756.html # Last updated: 2006-02-14 ...

  9. Power BI官方视频(3) Power BI Desktop 8月份更新功能概述

    Power BI Desktop 8月24日发布了更新版本.现将更新内容翻译整理如下,可以根据后面提供的链接下载最新版本使用. 1.主要功能更新 1.1 数据钻取支持在线版 以前的desktop中进行 ...

随机推荐

  1. webui layout like desktop rich client

    similarity similarlike desktop js frameworklike extj js frameworklike rich client js frameworkjs lay ...

  2. Linux系统的启动流程以及做个小小的Linux

    内核的作用     进程管理:进程间切换     内存管理:内存空间分割为内核空间和用户空间     IO管理:对底层硬件的使用必须由内来实现,不能由用户空间进程来实现     文件系统管理     ...

  3. PHP AOP

    看到一篇好文,果断收藏 点击打开链接http://www.cnblogs.com/afritxia2008/archive/2010/07/03/1770427.html

  4. jQuery学习教程(2)

    由于一件事情打断了我的生活节奏,每天都学习都在托托拉拉,导致很多进度都没有达到自己预期的效果 在上一个章节我学到了环境的搭建,以及对jquery的熟悉.现在开始对其具体进行熟悉了. 一.如何使用选择器 ...

  5. 【转】Oracle job procedure 存储过程定时任务

    原文:Oracle job procedure 存储过程定时任务 oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相 ...

  6. 测试php页面执行代码时间

    //生命一个计算脚本运行时间的类 class Timer { private $startTime = 0; //保存脚本开始执行时的时间(以微秒的形式保存) private $stopTime = ...

  7. PHP接口(interface)和抽象类(abstract)

    interface 定义了一个接口类,它里面的方法其子类必须实现.接口是类的一个模板,其子类必须实现接口中定义的所有方法. interface User{     function getHeight ...

  8. 阻止CSS样式被缓存

    <link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" typ ...

  9. php实现手机拍照上传头像功能

    现在手机拍照很火,那么如何使用手机拍照并上传头像呢?原因很简单,就是数据传递,首先手机传递照片信息,这个就不是post传递 也不是get函数传递, 这个另外一种数据格式传递,使用的是$GLOBALS ...

  10. ajax 同步异步调用