当前位置:网站首页>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 .
边栏推荐
- 游戏出海,全球化运营
- Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
- 自主工业软件的创新与发展
- Programmer anxiety
- 中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
- MongoDB常用28条查询语句(转)
- 小程序直播 + 电商,想做新零售电商就用它吧!
- Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
- R语言dplyr包summarise_if函数计算dataframe数据中所有数值数据列的均值和中位数、基于条件进行数据汇总分析(Summarize all Numeric Variables)
- MySQL8版本免安装步骤教程
猜你喜欢
gin集成支付宝支付
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
10.(地图数据篇)离线地形数据处理(供Cesium使用)
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
测试流程整理(3)
数据仓库面试问题准备
[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
为什么图片传输要使用base64编码
随机推荐
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
markdown 语法之字体标红
MySQL之详解索引
JVM memory layout detailed, illustrated, well written!
docker-compose公网部署redis哨兵模式
golang fmt.printf()(转)
GCC【6】- 编译的4个阶段
1200. Minimum absolute difference
Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
MySQL 5 installation and modification free
R语言dplyr包summarise_if函数计算dataframe数据中所有数值数据列的均值和中位数、基于条件进行数据汇总分析(Summarize all Numeric Variables)
Unity Shader学习(三)试着绘制一个圆
Test evaluation of software testing
ARouter的使用
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT