当前位置:网站首页>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 .
边栏推荐
- Introducing testfixture into unittest framework
- 使用默认路由作为指向Internet的路由
- Mask wearing detection based on yolov1
- 按照功能对Boost库进行分类
- 自主工业软件的创新与发展
- 1200. Minimum absolute difference
- R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
- Unity shader learning (3) try to draw a circle
- 软件测试之测试评估
- Error in find command: paths must precede expression (turn)
猜你喜欢
基于PaddleX的智能零售柜商品识别
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
MySQL 5 installation and modification free
软件测试之测试评估
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
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
国内酒店交易DDD应用与实践——代码篇
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
Unity shader learning (3) try to draw a circle
随机推荐
做事的真正意义和目的,真正想得到什么
Unity Shader学习(三)试着绘制一个圆
2022游戏出海实用发行策略
xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
Gorm data insertion (transfer)
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
TestSuite and testrunner in unittest
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
IP 实验室月复盘 · 第 5 期
Xcode 异常图片导致ipa包增大问题
1200. 最小绝对差
MATLAB中tiledlayout函数使用
小程序直播 + 电商,想做新零售电商就用它吧!
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
IDEA快捷键大全
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
392. 判断子序列
MySQL version 8 installation Free Tutorial