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. IOS_OC_百度地图与社交分享

    前奏. 知识点介绍 一. 导航和画线 地图画线 (理解) 二. 百度地图 集成百度地图 (掌握) POI检索 (掌握) 三. 社交分享 系统自带分享 (了解) 友盟分享 (掌握) SSO授权 (理解) ...

  2. iOS开发——JS网页交互——javaScript

    JS中调用OC #import "ViewController.h" @interface ViewController () <UIWebViewDelegate> ...

  3. O-C相关-06:对象与对象的关系

    对象与对象的关系 1.对象与对象的关系 依赖 关联 组合 常常讨论对象与对象关系时会提供两个属于:内聚性,耦合性 内聚一般指功能上的指向性 耦合一般指关联上的依赖性 2.依赖: 对象之间最弱的一种关联 ...

  4. java时间格式大全

    java.util.*;import java.text.*;import java.util.Calendar; public class VeDate { /**  * 获取现在时间  *   * ...

  5. Token 的作用

    Token,就是令牌,最大的特点就是随机性,不可预测.一般黑客或软件无法猜测出来. 那么,Token有什么作用?又是什么原理呢? Token一般用在两个地方: 1)防止表单重复提交. 2)anti c ...

  6. 暑假集训(1)第四弹 -----Find a way(Hdu2612)

    Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...

  7. SQL Function(方法)

    1.为什么有存储过程(procedure)还需要(Function) fun可以再select语句中直接调用,存储过程是不行的. 一般来说,过程显示的业务更为复杂:函数比较有针对性. create f ...

  8. iOS 改变UILabel部分颜色

    //协议 UILabel *xieLabel = [[UILabel alloc] init]; xieLabel.textColor = TextGrayColor; xieLabel.font = ...

  9. SEVERE: Error listenerStart

    转载:http://blog.sina.com.cn/s/blog_43eb83b90102e2k6.html# 今天启动Tomcat启动不了,报以下错:org.apache.catalina.cor ...

  10. Kaggle Competition Past Solutions

    Kaggle Competition Past Solutions We learn more from code, and from great code. Not necessarily alwa ...