PDA

View Full Version : Computationally inexpensive (lossy) method of screenshot and/or movie?



Mr_Cloud
13th August 2014, 16:43
Hello,

I'm trying to sequentially grab screenshots and send them to a label located on the GUI. The purpose is to eventually write a program which records the screen.

I've successfully achieved this with QPixmap's grabWindow, only it is quite slow and not very framerate friendly (I would love some 20-30fps). I've also noticed that grabWindow hides the mouse before taking a screenshot, which is a great feature usually but doesn't interest me. Also, seeing as it is a QPixmap feature, it is safe to assume that lossless (png?) screenshots are taken, which means 6meg or more per 1080p screen.

Here is my code so far:


//mw.h
#include <QtGui/QMainWindow>
#include <QApplication>
#include <QPixmap>
#include <QWidget>
#include <QtGui>
#include <QTimer>

namespace Ui
{
class mw;
}

class mw : public QMainWindow
{
Q_OBJECT

public:
mw(QWidget *parent = 0);
~mw();
QTimer *derp;

public slots:
void process();

private:
Ui::mw *ui;
};




//mw.cpp
using namespace std;

mw::mw(QWidget *parent)
: QMainWindow(parent), ui(new Ui::mw)
{
ui->setupUi(this);

derp=new QTimer;
connect(derp,SIGNAL(timeout()),this,SLOT(process() ));
derp->start(50); //20fps
}

mw::~mw()
{
delete ui;
}

void mw::process(){
ui->label->setPixmap(QPixmap::grabWindow(QApplication::deskto p()->winId()).scaled(ui->label->size(),Qt::KeepAspectRatio,Qt::SmoothTransformatio n));
}


What would be an alternative to lossless, CPU-intensive screenshots? Would Qt support taking jpg screenshots instead of png? Or perhaps it could be done with OpenGL somehow? Perhaps even QImageWriter?

Thanks in advance.


Regards,
Mr_Cloud

anda_skoa
14th August 2014, 12:10
A screenshot is just pixel data, it is not in any image storage format.
You can decide which format to save to.

http://qt-project.org/doc/qt-5/QImage.html#reading-and-writing-image-files

Cheers,
_