惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
雷峰网
雷峰网
月光博客
月光博客
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
美团技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
A
Arctic Wolf
Latest news
Latest news
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
F
Fortinet All Blogs
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
Help Net Security
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 【当耐特】
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
H
Help Net Security
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog

博客园 - 天涯

Prism.Interactivity 和 Prism.Modularity 介绍 Prism BindableBase 和 Commands 的介绍 对 mvvm 架构的理解 wpf mvvm 架构 C#硬件开发业务流程调试技巧 wpf Cannot locate resource 'app.xaml' app.config ConfigSection 保护 程序开发注意4项,你知道吗? .net 变量缓存,你知道吗 wpf 多线程 更新UI 界面 wpf treeview 绑定不同的对象 .net 技术,你掌握了多少 aspx 中确认删除 脚本 - 天涯 .net 中对类的扩展 奇怪--ORA-12154:TNS:无法处理服务名: 建模十条原则 由软件加壳谈起 Hashtable 应注意的 2 点 vb 调用c#做的com 组件
wpf winform 截图
天涯 · 2020-05-03 · via 博客园 - 天涯

 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