In the project, we have the need to record the screen, there are several ways to record the screen, can be based on Windows API BitBlt, FFmpeg Avdevice, DirectX and QT, this article explains the QT5-based capture screen. The advantages of QT relative to other kinds of screen-catching are better cross-platform, simple interface, inferior to DirectX capture screen, but DirectX can only be windows. After testing DirectX capture screen speed is the fastest, the other interface speed is basically the same.
QT 1080P screen capture on my computer consumes 60~80 milliseconds, 720p consumes 30~50, that is, if you capture screen 1080 I record up to 10 frames a second. This performance should be good, otherwise it will cause blocking.
Get home Screen
QScreen *SCR = qguiapplication::p rimaryscreen ();
Screen capture
Qpixmap pix= Scr->grabwindow (qapplication::d esktop ()->winid ());
Just two lines of code is very simple, after the capture of the data in the PIX, the Qpixmap converted to Qimage can be taken to the RGB data.
Qimage img= pix.toimage ();
Uchar *date = Img.bits ();
After taking the screenshot data, we are going to encode compression, encoding can use ffmpeg, need to determine the data format to get, can be obtained through the Img.format members, my side is format_rgb32. It is also important to note that the image data in Qt does not have to be continuously stored per pixel, each line is 4 aligned, and the simplest solution is to ensure that the width of your image is a multiple of 4. If there is no guarantee, you can get the number of bytes per row by Img.bytesperline ().
void Qtscreen::p aintevent (qpaintevent *event)
{
QScreen *SCR = qguiapplication::p rimaryscreen ();
Screen capture
Qpixmap pix= Scr->grabwindow (qapplication::d esktop ()->winid ());
Qimage img= pix.toimage ();
Qpainter p;
P.begin (this);
P.drawimage (qpoint (0, 0), Qi);
P.end ();
}
More information can also focus on my 51CTO video course
Summer Teacher's Classroom http://edu.51cto.com/lecturer/index/user_id-12016059.html
C + + cross-platform development and audio and video combat theme packagesC + + combat ffmpeg Audio Video Coding video lesson-based on QT5 and FFmpeg SDK
Http://edu.51cto.com/course/10359.html
650) this.width=650; "src=" Https://s1.51cto.com/images/201706/30/1406b01a322070e017b12a6e0f05c8d9.png "style=" FLOAT:LEFT;WIDTH:500PX;HEIGHT:299PX, "title=" "alt=" 1406b01a322070e017b12a6e0f05c8d9.png "width=" "vspace=" 0 " Hspace= "0" height= "299" border= "0"/>
This article is from the "Xia Chaojun" blog, make sure to keep this source http://xiacaojun.blog.51cto.com/12016059/1951341
C + + programming uses the QT5 SDK to record the screen and display