wpf winform 截图
wpf 通过下面的截图,标题可能会丢失。
public void CreateBitmapFromVisual(Window win, string fileName)
{
if (win == null || string.IsNullOrEmpty(fileName))
{
return;
}
int index = fileName.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
if (index > 0)
{
string tmpPath = fileName.Substring(0, index);
if (!Directory.Exists(tmpPath))
{
Directory.CreateDirectory(tmpPath);
}
}
RenderTargetBitmap renderTarget = new RenderTargetBitmap((Int32)win.Width, ((Int32)win.Height), 96, 96, PixelFormats.Pbgra32);
renderTarget.Render(win);
PngBitmapEncoder bitmapEncoder = new PngBitmapEncoder();
bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
using (Stream stm = File.Create(fileName))
{
bitmapEncoder.Save(stm);
}
}
wpf 通过下面的截图,可能会截的多余或是少 的
public void CreateBitmapFromVisual(Window win, string fileName)
{
if (win == null || string.IsNullOrEmpty(fileName))
{
return;
}
int index = fileName.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
if (index > 0)
{
string tmpPath = fileName.Substring(0, index);
if (!Directory.Exists(tmpPath))
{
Directory.CreateDirectory(tmpPath);
}
}
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
float systemdpi = graphics.DpiX / 96;
var bitmap = new System.Drawing.Bitmap((int) (win.Width* systemdpi), (int)(win.Height* systemdpi), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (System.Drawing.Graphics memoryGrahics = System.Drawing.Graphics.FromImage(bitmap))
{
memoryGrahics.CopyFromScreen((int)Math.Round(win.Left), (int)Math.Round(win.Top), 0, 0, new System.Drawing.Size((int)(win.Width* systemdpi), (int)(win.Height* systemdpi)), System.Drawing.CopyPixelOperation.SourceCopy);
}
bitmap.Save(fileName);
}
原因是 double 转化成 int ,造成位置信息错误,出现截图错误。神奇的 windows
wpf winform 截图的更多相关文章
- WPF 完美截图 <二>
根据WPF 完美截图 <一>总结: 1.BitmapSource与BitmapImage及CorppedBitmap之间的转换 2.中心及边角的模板实现及其拖动 3.除了拖动矩形外区域要实 ...
- WPF C#截图功能 仿qq截图
原文:WPF C#截图功能 仿qq截图 先上效果图 源码下载地址:http://download.csdn.net/detail/candyvoice/9788099 描述:启动程序,点击窗口butt ...
- C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法的示例与源码下载带详细注释-源码代码-注册表方式-启动目录快捷方式
C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法的示例与源码下载带详细注释-源码代码-注册表方式-启动目录快捷方式 C#实现自动启动的方法-两种方法 源码下载地址: ...
- 采用WPF开发截图程序,so easy!
前言 QQ.微信截图功能已很强大了,似乎没必要在开发一个截图程序了.但是有时QQ热键就是被占用,不能快速的开启截屏:有时,天天挂着QQ,领导也不乐意.既然是程序员,就要自己开发截屏工具,功能随心所欲 ...
- 富客户端 wpf, Winform 多线程更新UI控件
前言 在富客户端的app中,如果在主线程中运行一些长时间的任务,那么应用程序的UI就不能正常相应.因为主线程要负责消息循环,相应鼠标等事件还有展现UI. 因此我们可以开启一个线程来格外处理需要长时间的 ...
- C# webBrowser(wpf/winform) 互调js
1.winform [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [ComVisible(true)] pu ...
- WPF&Winform版本地图引擎
最近几年一直从事地图方面的工作,自主研发了WPF和Winform两个版本瓦片地图引擎.轻量级.不依赖第三库.先上一张图片展示一下吧! 产品包括服务端和客户端两部份: 1.服务端主要地图图层配制和空间计 ...
- C# winform截图、web Cropper图片剪切、上传
今天又来一弹,写了个小功能,windows 桌面截图,web剪切图片上传的功能. 废话不多说,直接上图: 1.winform 截屏功能 图1 主窗体 点击全屏截图,就已经全屏截图了,截图后,图片保存在 ...
- wpf/winform获取windows10系统颜色和主题色
Windows10开始微软在系统颜色中添加了深色,对于UWP来说很轻松就能获取到系统当前的颜色和主题色,而对于Win32应用就没有那么直观了. 在wpf中,可以通过SystemParameters.W ...
随机推荐
- SMTP发邮件(直接可用)实例
string file = "邮件测试.txt";//放在Debug下的一个txt文件. MailAddress from = new MailAddress("自己的邮 ...
- Java中常量的概念
常量:在程序执行过程中,其值不发生改变的量.分类:A:字面值常量B:自定义常量字面值常量A:字符串常量(用“”括起来的内容).举例:"hello"B:整数常量 (所有的整数)举例: ...
- Centos8安装Docker提示:package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
Centos8安装Docker提示:package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but ...
- 负载均衡服务之HAProxy基础配置(四)
前文我们聊了haproxy的状态页配置,状态页中显示各参数的含义,以及基于cookie做会话保持的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12776 ...
- 手把手编写自己的PHP MVC框架实例教程
1 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式. MVC把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Contro ...
- thinkphp 5 一些常见问题
## 请求缓存 request_cache
- php内置函数call_user_func()
<?php //call_user_func(callback,name,age) //第一个参数callback作为回掉函数使用,其余的参数是他的参数 function now($a,$b) ...
- Visual Studio 2015 + Windows 2012 R2, c++/cli Array::Sort() 抛出异常
在Windows7上编译就是正常. 可见Windows2012 R2缺少了一些东西. 另外,有一个现象一样,但原因不一样的 https://stackoverflow.com/questions/46 ...
- 学习web前端的roadmap
- Linux系统应用管理:增加普通用户(密码管理等)
1. 查看当前Linux系统的版本.内核等信息 [root@oldboy ~]# cat /etc/redhat-release CentOS release 6.7 (Final) . # 系统版本 ...