Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement screen recording Control by Qt

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Qt how to achieve screen recording control, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

I. Preface

In the usual writing process, it is often necessary to capture screenshots of some operation actions and effects into gif format to make the covered information more comprehensive and vivid. Sometimes the whole operation process and running effect can be recorded into MP4, but the file size is relatively large, and many websites are not easy to upload, basically support gif dynamic images, generally a 5-second gif,800*600 resolution, can be well controlled in 500KB In this way, it is more perfect to support the drive map on the major websites. At the beginning of the use of ScreenGif.exe, used for a long time, feel OK, after a friend recommended to use LICEcap.exe, smaller, higher compression ratio, and then later found that there is an open source gif.h class, which can be implemented by calling the method to merge multiple images into a gif, and is cross-platform, I personally successfully tested in WIN+UBUNTU. The original code was given by Hero Ni, and I improved it on this basis so that I can directly drag the size of the form to change the size of the screencap area. Added support for Qt4 and other compilers.

Main functions:

The width and height of the screen to be recorded can be set to support direct pull changes in the lower right corner.

Width that can be set to widen

The background color of the screencap control can be set.

The number of frames recorded can be set.

The recording area can be dragged freely.

2. Void GifWidget::saveImage () {if (! gifWriter) {return;} # if (QT_VERSION grabWindow (0, x () + rectGif.x (), y () + rectGif.y (), rectGif.width (), rectGif.height ()); QImage image = pix.toImage (). ConvertToFormat (QImage::Format_RGBA8888); # endif gif.GifWriteFrame (gifWriter, image.bits (), rectGif.width (), rectGif.height (), fps); count++ LabStatus- > setText (QString ("recording frame% 1") .arg (count);} void GifWidget::record () {if (btnStart- > text () = = "start") {if (0! = gifWriter) {delete gifWriter; gifWriter = 0 } / / File Save dialog box / / fileName = qApp- > applicationDirPath () + "/" + QDateTime::currentDateTime () .toString ("yyyy-MM-dd-hh-mm-ss.gif"); fileName = QFileDialog::getSaveFileName (this, "Select Save location", qApp- > applicationDirPath () + "/", "gif Picture (* .gif)") If (fileName.isEmpty ()) {return;} int width = txtWidth- > text (). ToInt (); int height = txtHeight- > text (). ToInt (); fps = txtFps- > text (). ToInt (); gifWriter = new Gif::GifWriter; bool bOk = gif.GifBegin (gifWriter, fileName.toLocal8Bit (). Data (), width, height, fps) If (! bOk) {delete gifWriter; gifWriter = 0; return;} count = 0; labStatus- > setText ("start recording..."); btnStart- > setText ("stop"); / / delayed startup timer- > setInterval (1000 / fps); QTimer::singleShot (1000, timer, SLOT (start () / / saveImage ();} else {timer- > stop (); gif.GifEnd (gifWriter); delete gifWriter; gifWriter = 0; labStatus- > setText (QString ("recording completed 1 frame") .arg (count)); btnStart- > setText ("start"); QDesktopServices::openUrl (QUrl (fileName));} third, effect

Thank you for reading this article carefully. I hope the article "how to implement screen recording controls in Qt" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report