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. 硬盘性能测试工具之bonnie++

    bonnie++ 官方站点 先写内存的两倍,内存较大时比较耗时.适合简单的测试场景. # bonnie++ -u root 写测试 读测试 Version 1.97 ------Sequential ...

  2. 新的知识点来了-ES6 Proxy代理 和 去银行存款有什么关系?

    ES给开发者提供了一个新特性:Proxy,就是代理的意思.也就是我们这一节要介绍的知识点. 以前,ATM还没有那么流行的时候(暴露年纪),我们去银行存款或者取款的时候,需要在柜台前排队,等柜台工作人员 ...

  3. 【<meta name="" content=">】的作用

    一.语法: <meta name="name" content="string"/> 二.参数解析: 1.name项:常用的选项有keywords( ...

  4. thinkphp--多个id查询

    $feedback_list = $feedback -> where( array("member_id"=>array("in", " ...

  5. python学习14集合

    '''''''''集合:set1.定义:是一个无序的不重复元素序列.2.表示:大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用 ...

  6. @SessionAttributes 和 @SessionAttribute的区别

    @SessionAttributes 和 @SessionAttribute的区别 Spring MVC中有两个长得非常像的注解:@SessionAttributes 和 @SessionAttrib ...

  7. 【杂谈】从实现角度看ChannelFuture

    JDK中的Future特性 在介绍Netty的ChannelFuture之前,我们先来看看JDK中的Future是如何实现的.总的来说就是任务提交的时候会使用装饰器模式,将任务包装成一个FutureT ...

  8. Codeforces Round #590

    题目链接:Round #590 题目答案:官方Editorial.My Solution A. Equalize Prices Again 签到题还WA了一发,向上取整有点问题: //my wrong ...

  9. 概率dp部分题目

    记录一些比较水不值得单独写一篇blog的概率dp题目 bzoj3036 绿豆蛙的归宿 Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向 ...

  10. SVN 部署(基于 Linux)

    1.通过 yum 命令安装 svnserve,命令如下: # 此命令会全自动安装svn服务器相关服务和依赖,安装完成会自动停止命令运行 yum -y install subversion # 若需查看 ...