当前位置:网站首页>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 .
边栏推荐
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- 【C 题集】of Ⅶ
- R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
- 吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
- 奇妙秘境 码蹄集
- IP 实验室月复盘 · 第 5 期
- Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
- 2022游戏出海实用发行策略
- Xcode 异常图片导致ipa包增大问题
- Whether the loyalty agreement has legal effect
猜你喜欢

C# wpf 实现截屏框实时截屏功能

数据仓库面试问题准备

好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人

【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结

自主工业软件的创新与发展

Unity Shader学习(三)试着绘制一个圆

China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

Innovation and development of independent industrial software
![Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
随机推荐
golang fmt.printf()(转)
Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
学习项目是自己找的,成长机会是自己创造的
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
go语言中的文件创建,写入,读取,删除(转)
读取 Excel 表数据
Xcode 异常图片导致ipa包增大问题
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
硬件基础知识-二极管基础
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
如何游戏出海代运营、游戏出海代投
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
Basic mode of service mesh
[C question set] of VII
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
MATLAB中tiledlayout函数使用