简化版:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging; namespace ConsoleApp346
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ScreenCapture(); } static void ScreenCapture()
{
Rectangle bounds = Screen.GetBounds(System.Drawing.Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, bounds.Size);
}
string fullName = Directory.GetCurrentDirectory() + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
bitmap.Save(fullName, ImageFormat.Jpeg);
}
}
}
}

效果如图:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

namespace ConsoleApp346
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ScreenCapture();

}

static void ScreenCapture()
{
Rectangle bounds = Screen.GetBounds(System.Drawing.Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, bounds.Size);
}

using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Title = "Save Pictures";
sfd.InitialDirectory = Directory.GetCurrentDirectory();
sfd.RestoreDirectory = true;
sfd.Filter = "bmp files(*.bmp)|*.bmp|All Files(*.*)|*.*";
sfd.FileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
if (sfd.ShowDialog() == DialogResult.OK)
{
bitmap.Save(sfd.FileName, ImageFormat.Jpeg);
}
}
}
}
}
}

效果如下所示:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging; namespace ConsoleApp346
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ScreenCapture(); } static void ScreenCapture()
{
Rectangle bounds = Screen.GetBounds(System.Drawing.Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, bounds.Size);
} using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Title = "Save Pictures";
sfd.InitialDirectory = Directory.GetCurrentDirectory();
sfd.RestoreDirectory = true;
sfd.Filter = "bmp files(*.bmp)|*.bmp|All Files(*.*)|*.*";
sfd.FileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
if (sfd.ShowDialog() == DialogResult.OK)
{
bitmap.Save(sfd.FileName, ImageFormat.Jpeg);
}
}
}
}
}
}

C# 截图ScreenCapture,保存的更多相关文章

  1. [Android] 拍照、截图、保存并显示在ImageView控件中

    近期在做Android的项目,当中部分涉及到图像处理的内容.这里先讲述怎样调用Camera应用程序进行拍照,并截图和保存显示在ImageView控件中以及遇到的困难和解决方法.     PS:作者购买 ...

  2. opencv 截图并保存

    opencv 截图并保存(转载) 代码功能:选择图像中矩形区,按S键截图并保存,Q键退出. #include<opencv2/opencv.hpp> #include<iostrea ...

  3. html2canvas插件对整个网页或者网页某一部分截图并保存为图片

    html2canvas能够实现在用户浏览器端直接对整个或部分页面进行截屏.这个脚本将当前页面渲染成一个canvas图片,通过读取DOM并将不同的样式应用到这些元素上实现.它不需要来自服务器任何渲染,整 ...

  4. 对html进行截图并保存为本地图片

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. Unity3D随意截图并保存

    http://blog.csdn.net/awnuxcvbn/article/details/9199245 效果 代码 <pre name="code" class=&qu ...

  6. Python+Selenium练习篇之21-如何截图并保存

    本文介绍如何利用Selenium的方法进行截图,在测试过程中,是有必要截图,特别是遇到错误的时候进行截图.在selenium for python中主要有三个截图方法,我们挑选其中最常用的一种. ge ...

  7. Python3.X Selenium 自动化测试中如何截图并保存成功

    在selenium for python中主要有三个截图方法,我们挑选其中最常用的一种. 挑最常用的:get_screenshot_as_file() 相关代码如下:(下面的代码可直接复制) # co ...

  8. selenium 页面截图并保存

    import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org. ...

  9. 利用HTML5的Video进行视频截图并保存到本地

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

随机推荐

  1. Python入门36道经典练习题

    [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? num_list=[] cou=0 for i in range(1,5): for j in rang ...

  2. Vue中计算属性、侦听、过滤、自定义指令、ref的操作

    1.计算属性 <div id="app"> <input type="text" v-model="x"> < ...

  3. 仅用StoryBoard布局实现按钮的均匀分布

    今天在做登录界面时设计的需求是,登录和取消按钮左右对称均匀分布,按钮大小不变如图 屏幕宽度变化时按钮宽度不变,三个间距相等并且随屏幕变化而变化,简单的说就是按钮均匀分布,在网上查了一些资料,弄得比较乱 ...

  4. Android SearchView不显示搜索icon

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/80 背景: 之前碰到了一个页面展示问题,SearchVie ...

  5. Linux--NIS

    一. 环境准备 操作系统:CentOS7.6 服务端安装如下软件: 软件名称 功能 ypserv NIS Server端的服务进程 rpcbind 提供RPC服务 客户端安装如下软件: 软件名称 功能 ...

  6. asp.net core全局异常过滤并监控系统BUG将异常信息记录到日志

    添加: using Dw.Util.Helper; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collect ...

  7. STL关联容器的基本操作

    关联容器 map,set map map是一种关联式容器包含 键/值 key/value 相当于python中的字典不允许有重复的keymap 无重复,有序 Map是STL的一个关联容器,它提供一对一 ...

  8. python 实用小技巧

    1. 列表 #以下三式等价 c = (a>b and a or b) c = a if a>b else b c = [b, a][a>b] 字符串拼接 ' + '.join('%s ...

  9. Markdown & LaTex 常用语法

    目录 blog 的目录 博客园自带目录 用 javascript 自定义目录 主标题 副标题 h1,一级标题 h2,二级标题 h3,三级标题 注释 常用的符号及文本形式 如果你想在markdown中文 ...

  10. php 学习笔记之日期时间操作一箩筐

    格式化日期时间 date : 格式化日期时间 场景 将当前日期时间或者特定日期时间格式化输出为特定格式的字符串,常用于人性化展示信息. 说明 返回给定时间戳格式化后所产生的日期时间字符串,如果没有给出 ...