当前位置:网站首页>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 .
边栏推荐
- [FAQ] summary of common causes and solutions of Huawei account service error 907135701
- 去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- 学内核之三:使用GDB跟踪内核调用链
- 使用默认路由作为指向Internet的路由
- R语言ggplot2可视化:gganimate包创建动画图(gif)、使用anim_save函数保存gif可视化动图
- MATLAB中tiledlayout函数使用
- Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
- Basic mode of service mesh
- sharding key type not supported
猜你喜欢

学内核之三:使用GDB跟踪内核调用链

MySQL version 8 installation Free Tutorial

Innovation and development of independent industrial software

How to package QT and share exe
![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)]

10.(地图数据篇)离线地形数据处理(供Cesium使用)

vscode 常用插件汇总

DDD application and practice of domestic hotel transactions -- Code

德明利深交所上市:市值31亿 为李虎与田华夫妻档

软件测试之测试评估
随机推荐
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
Unity Shader学习(三)试着绘制一个圆
IP lab monthly resumption · issue 5
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
软件测试之测试评估
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
【C 题集】of Ⅶ
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
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
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
QT how to detect whether the mouse is on a control
92.(cesium篇)cesium楼栋分层
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
php 日志调试
Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
qt 怎么检测鼠标在不在某个控件上
mac redis安装与使用,连接远程服务器 redis