-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdesktopcap.cpp
More file actions
42 lines (39 loc) · 1003 Bytes
/
desktopcap.cpp
File metadata and controls
42 lines (39 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "desktopcap.h"
DesktopCap::DesktopCap(){
desk = QApplication::desktop();
screen =QApplication::primaryScreen();
timer=new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(worker()));
}
DesktopCap::~DesktopCap(){
// delete desk;
// delete screen;
}
int DesktopCap::init(int width, int height){
this->width=width;
this->height=height;
size=width*height*3;
return size;
}
void DesktopCap::doCap(){
timer->start(40);
buf=new unsigned char[size];
}
void DesktopCap::doStop(){
timer->stop();
msleep(20);
delete [] buf;
}
void DesktopCap::worker(){
if(screen){
pix=screen->grabWindow(desk->winId(),0,0,desk->width(),desk->height()).scaled(width,height);
img=pix.toImage().convertToFormat(QImage::Format_RGB888);
memcpy(buf,img.constBits(),size);
emit capFinish();
}
}
void DesktopCap::getFrame(unsigned char *&framebuff){
if(framebuff==NULL)
return;
memcpy(framebuff,buf,size);
}