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 截图的更多相关文章

  1. WPF 完美截图 <二>

    根据WPF 完美截图 <一>总结: 1.BitmapSource与BitmapImage及CorppedBitmap之间的转换 2.中心及边角的模板实现及其拖动 3.除了拖动矩形外区域要实 ...

  2. WPF C#截图功能 仿qq截图

    原文:WPF C#截图功能 仿qq截图 先上效果图 源码下载地址:http://download.csdn.net/detail/candyvoice/9788099 描述:启动程序,点击窗口butt ...

  3. C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法的示例与源码下载带详细注释-源码代码-注册表方式-启动目录快捷方式

    C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法的示例与源码下载带详细注释-源码代码-注册表方式-启动目录快捷方式 C#实现自动启动的方法-两种方法 源码下载地址: ...

  4. 采用WPF开发截图程序,so easy!

    前言  QQ.微信截图功能已很强大了,似乎没必要在开发一个截图程序了.但是有时QQ热键就是被占用,不能快速的开启截屏:有时,天天挂着QQ,领导也不乐意.既然是程序员,就要自己开发截屏工具,功能随心所欲 ...

  5. 富客户端 wpf, Winform 多线程更新UI控件

    前言 在富客户端的app中,如果在主线程中运行一些长时间的任务,那么应用程序的UI就不能正常相应.因为主线程要负责消息循环,相应鼠标等事件还有展现UI. 因此我们可以开启一个线程来格外处理需要长时间的 ...

  6. C# webBrowser(wpf/winform) 互调js

    1.winform [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [ComVisible(true)] pu ...

  7. WPF&Winform版本地图引擎

    最近几年一直从事地图方面的工作,自主研发了WPF和Winform两个版本瓦片地图引擎.轻量级.不依赖第三库.先上一张图片展示一下吧! 产品包括服务端和客户端两部份: 1.服务端主要地图图层配制和空间计 ...

  8. C# winform截图、web Cropper图片剪切、上传

    今天又来一弹,写了个小功能,windows 桌面截图,web剪切图片上传的功能. 废话不多说,直接上图: 1.winform 截屏功能 图1 主窗体 点击全屏截图,就已经全屏截图了,截图后,图片保存在 ...

  9. wpf/winform获取windows10系统颜色和主题色

    Windows10开始微软在系统颜色中添加了深色,对于UWP来说很轻松就能获取到系统当前的颜色和主题色,而对于Win32应用就没有那么直观了. 在wpf中,可以通过SystemParameters.W ...

随机推荐

  1. MySQL笔记总结-DDL语言

    DDL语言 数据类型 一.数值型 1.整型 tinyint.smallint.mediumint.int/integer.bigint 1 2 3 4 8 特点: ①都可以设置无符号和有符号,默认有符 ...

  2. Python数据预处理:使用Dask和Numba并行化加速

    如果你善于使用Pandas变换数据.创建特征以及清洗数据等,那么你就能够轻松地使用Dask和Numba并行加速你的工作.单纯从速度上比较,Dask完胜Python,而Numba打败Dask,那么Num ...

  3. 2019-2020-1 20199308《Linux内核原理与分析》第九周作业

    <Linux内核分析> 第八章 可执行程序工作原理进程的切换和系统的一般执行过程 8.1 知识点 进程调度的时机 ntel定义的中断类型主要有以下几种 硬中断(Interrupt) 软中断 ...

  4. C#多线程(16):手把手教你撸一个工作流

    目录 前言 节点 Then Parallel Schedule Delay 试用一下 顺序节点 并行任务 编写工作流 接口构建器 工作流构建器 依赖注入 实现工作流解析 前言 前面学习了很多多线程和任 ...

  5. nginx与keepalived实现高可用+Apache实现负载均衡

    nginx与keepalived实现高可用 本实验使用了四台虚拟机 两台需要安装nginx及keepalived 两台安装Apache nginx可以源码安装也可以用yum安装nginx yum安装n ...

  6. tomcat启动日志中中文乱码

    场景 使用catalina.bat start命令启动tomcat7 方案 打开%catalina_home%/conf/logging.properties文件. 将其中的UTF-8代换为GBK. ...

  7. 谷歌浏览器报错Unchecked runtime.lastError: The message port closed before a response was received.。

    浏览器版本 : 报错原因:扩展程序问题 解决建议:打开chrome://extensions/,逐一关闭排查

  8. Spring IOC 之注册解析的 BeanDefinition

    2019独角兽企业重金招聘Python工程师标准>>> DefaultBeanDefinitionDocumentReader.processBeanDefinition() 完成 ...

  9. Next.js 7发布,构建速度提升40%

    Next.js团队发布了其开源React框架的7版本.该版本的Next.js主要是改善整体的开发体验,包括启动速度提升57%.开发时的构建速度提升40%.改进错误报告和WebAssembly支持. \ ...

  10. 关于通过Date.getTime()得到1970年01月1日0点零分问题验证

     public static String getTimestamp_1970() throws Exception {   java.text.SimpleDateFormat formater = ...