当前位置:网站首页>C # WPF realizes the real-time screen capture function of screen capture box
C # WPF realizes the real-time screen capture function of screen capture box
2022-07-04 14:16:00 【CodeOfCC】
List of articles
Preface
stay 《C# wpf Use DockPanel Implement screenshot box 》 We implemented a screenshot box , Next, we need to realize the corresponding screen capture function . Get the screenshot area and use GDI+ screenshots , Here are some details to deal with , For example, hide the controls on the screenshot box to avoid occlusion , Deal with differences dpi The position of the coordinates under the .
One 、 Implementation steps
1、 Get the screenshot area
With 《C# wpf Use DockPanel Implement screenshot box 》 The interface of ,clipRect Is the screenshot area control object , The following two lines of code can get the exact screenshot area , And do not suffer dpi influence .
var leftTop = clipRect.PointToScreen(new Point(0, 0));
var rightBottom = clipRect.PointToScreen(new Point(clipRect.ActualWidth, clipRect.ActualHeight));
2、 Hide controls
We need hidden controls in the screenshot box , such as 8 Drag points or toolbars .
clipRect.Visibility = Visibility.Hidden;
(1) problem
It is invalid to directly hide the control and then take a screenshot . because wpf The rendering mechanism of is completely asynchronous , It is impossible to know the exact time when the drawing on the screen is completed . therefore The screenshot immediately after hiding will still capture the control .
(2) resolvent
The simple solution is to delay screenshots , After hiding the control 500 Screen capture in milliseconds . But this method is not stable , Especially in the production environment , Users' machines are various , As long as there is a little card, it will still come out bug.
The perfect solution is to use animation , We use the multi frame rendering feature of animation and the completion of event callback to obtain the time after the control is truly painted . The specific steps are as follows :
Hide controls -> Create animation -> register Completed event -> Start animation ->Completed Screenshot of the event
3、 screenshots
Use the screenshot area obtained in the above steps , combination 《C# wpf Use GDI+ Achieve screen capture 》 The simple screenshot in is completed . Restore the hidden control after screenshot .
Two 、 Complete code
https://download.csdn.net/download/u013113678/85855030
3、 ... and 、 Results the preview
summary
That's what we're going to talk about today , This article briefly introduces wpf Screenshot box screenshot method . Two details need to be noted , One is dpi Handle , One is control hiding .gdi+ Screenshots are relatively easy to achieve , Of course, the implementation of the screenshot box is still slightly difficult . Such a set of screen capture functions can be used for formal projects by simply expanding the functions .
边栏推荐
- 软件测试之测试评估
- MySQL version 8 installation Free Tutorial
- Product identification of intelligent retail cabinet based on paddlex
- Rich text editing: wangeditor tutorial
- MySQL8版本免安装步骤教程
- Learning projects are self-made, and growth opportunities are self created
- Unittest框架中引入TestFixture
- TestSuite and testrunner in unittest
- xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
- 学习项目是自己找的,成长机会是自己创造的
猜你喜欢
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
392. 判断子序列
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
瑞吉外卖笔记
1200. Minimum absolute difference
递增的三元子序列[贪心训练]
测试流程整理(3)
随机推荐
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
R语言ggplot2可视化:gganimate包创建动画图(gif)、使用anim_save函数保存gif可视化动图
MongoDB常用28条查询语句(转)
MySQL之详解索引
sharding key type not supported
R语言dplyr包summarise_if函数计算dataframe数据中所有数值数据列的均值和中位数、基于条件进行数据汇总分析(Summarize all Numeric Variables)
Excel快速合并多行数据
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
数据仓库面试问题准备
vscode 常用插件汇总
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
php 日志调试
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
golang fmt.printf()(转)
奇妙秘境 码蹄集
2022游戏出海实用发行策略
测试流程整理(2)
为什么图片传输要使用base64编码
Hardware Basics - diode Basics