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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* Copyright (c) 2012 Yoann Blein
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include "QtDesktopScreenGrabber.h"
#include <QImage>
#include <QPixmap>
#include <QApplication>
#include <QDesktopWidget>
#include <QPainter>
#include <QColor>
#include <Swiften/ScreenSharing/Image.h>
#include <Swiften/Base/Log.h>
namespace Swift {
QtDesktopScreenGrabber::QtDesktopScreenGrabber()
{
}
QtDesktopScreenGrabber::~QtDesktopScreenGrabber()
{
}
Image QtDesktopScreenGrabber::grab() const
{
QImage qImg = QPixmap::grabWindow(QApplication::desktop()->winId()).toImage();//.convertToFormat(QImage::Format_RGB888);
// QImage qImg("/home/yb/Images/wallpaper-1681250.jpg");
qImg = qImg.scaled(qImg.width() * 0.7, qImg.height() * 0.7, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// SWIFT_LOG(debug) << "Format RGB32: " << (qImg.format() == QImage::Format_RGB32) << std::endl;
// QImage qImg(1920, 1080, QImage::Format_RGB32);
// qImg.fill(QColor(qrand() % 255, qrand()%255, qrand()%255));
// QPainter p(&qImg);
// p.translate(qImg.width() / 2, qImg.height() / 2);
// p.setBrush(Qt::black);
// static int x = 0;
// static int y = 0;
// x = (x+50)%qImg.width();
// y = (y+50)%qImg.height();
// p.drawEllipse(x, y, 100, 100);
// for (int i = 0; i < 40; ++i) {
// p.setBrush(QColor(qrand() % 255, qrand()%255, qrand()%255));
// p.drawEllipse(qrand()%qImg.width(), qrand()%qImg.height(), qrand()%(qImg.width()/4), qrand()%(qImg.height()/4));
// }
// p.end();
qImg = qImg.convertToFormat(QImage::Format_RGB888);
// uchar* bits = qImg.bits();
// for (int i = 0; i < qImg.byteCount(); ++i) {
// bits[i] = qrand();
// }
return Image(qImg.width(), qImg.height(), qImg.constBits());
}
}
|