当前位置:网站首页>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 .
边栏推荐
- Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
- The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- 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
- GCC【6】- 编译的4个阶段
- xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
- 为什么图片传输要使用base64编码
- Ws2818m is packaged in cpc8. It is a special circuit for three channel LED drive control. External IC full-color double signal 5v32 lamp programmable LED lamp with outdoor engineering
- 2022游戏出海实用发行策略
- Common content type correspondence table
猜你喜欢

392. 判断子序列
![去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]

吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行

Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test

Mask wearing detection based on yolov1

MySQL5免安装修改

vscode 常用插件汇总

测试流程整理(3)

How to package QT and share exe

TestSuite and testrunner in unittest
随机推荐
C# wpf 实现截屏框实时截屏功能
Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
Assertion of unittest framework
10.(地图数据篇)离线地形数据处理(供Cesium使用)
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
MySQL8版本免安装步骤教程
TestSuite and testrunner in unittest
按照功能对Boost库进行分类
Can mortgage with housing exclude compulsory execution
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
Test evaluation of software testing
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
JVM 内存布局详解,图文并茂,写得太好了!
File creation, writing, reading, deletion (transfer) in go language
The font of markdown grammar is marked in red
Mongodb commonly used 28 query statements (forward)