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

推荐订阅源

Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
D
Docker
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
D
DataBreaches.Net
月光博客
月光博客
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
MyScale Blog
MyScale Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学

博客园 - Rock Wang

Asp.Net Core Web Api基于cookie的安全验证 C#语言新特性(6.0-8.0) C#中Struct和Class的区别 iOS真机调试之免费预配(Free provisioning) iOS真机调试 Spring Boot学习笔记(1) Java学习笔记(9) Java学习笔记(7) Java学习笔记(6) Java学习笔记(5) Java学习笔记(4) Idea常用功能汇总 Java学习笔记(3) Java学习笔记(2) Java学习笔记(1) 如何开发NPM包 支持续传功能的ASP.NET WEB API文件下载服务 ASP.NET MVC 阻止通过Url直接访问服务器上的静态文件 VS2013/VS2015/VS2017通过oschina托管代码
c#抓屏功能在DPI缩放后,截到的图片不完整的问题
Rock Wang · 2017-04-26 · via 博客园 - Rock Wang
        /// <summary>
        /// 获取屏幕快照
        /// </summary>
        /// <returns></returns>
        public static Bitmap GetScreenSnapshot()
        {
            Bitmap bitmap = null;
            try
            {
                Graphics g = Graphics.FromHwnd(IntPtr.Zero);
                //100%的时候,DPI是96;这条语句的作用时获取放大比例
                float factor = g.DpiX / 96;
                Rectangle rc = new Rectangle(0, 0, (int)(SystemParameters.PrimaryScreenWidth * factor), (int)(SystemParameters.PrimaryScreenHeight * factor));
                bitmap = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
                using (Graphics memoryGrahics = Graphics.FromImage(bitmap))
                {
                    memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);
                }
            }
            catch (Exception ex)
            {
                NlogHelper.Error("截屏失败", ex);
            }
            return bitmap;
        }