| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef MYCAPTURE_H |
| 5 |
#define MYCAPTURE_H |
| 6 |
|
| 7 |
#include <QLabel> |
| 8 |
#include <Qt3DRender/QRenderCapture> |
| 9 |
|
| 10 |
class MyCapture : public QObject |
| 11 |
{ |
| 12 |
Q_OBJECT |
| 13 |
public: |
| 14 |
MyCapture(Qt3DRender::QRenderCapture* capture, QLabel *imageLabel) |
| 15 |
: m_capture(capture) |
| 16 |
, m_reply(nullptr) |
| 17 |
, m_imageLabel(imageLabel) |
| 18 |
, m_continuous(false) |
| 19 |
{ |
| 20 |
} |
| 21 |
|
| 22 |
public slots: |
| 23 |
void onCompleted() |
| 24 |
{ |
| 25 |
QObject::disconnect(connection); |
| 26 |
|
| 27 |
m_imageLabel->setPixmap(QPixmap::fromImage(m_reply->image())); |
| 28 |
|
| 29 |
m_reply->saveImage("capture.bmp"); |
| 30 |
|
| 31 |
m_reply->deleteLater(); |
| 32 |
m_reply = nullptr; |
| 33 |
|
| 34 |
if (m_continuous) |
| 35 |
capture(); |
| 36 |
} |
| 37 |
|
| 38 |
void setContinuous(bool continuos) |
| 39 |
{ |
| 40 |
m_continuous = continuos; |
| 41 |
} |
| 42 |
|
| 43 |
void capture() |
| 44 |
{ |
| 45 |
if (!m_reply) { |
| 46 |
m_reply = m_capture->requestCapture(); |
| 47 |
connection = QObject::connect(m_reply, &Qt3DRender::QRenderCaptureReply::completed, |
| 48 |
this, &MyCapture::onCompleted); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
private: |
| 53 |
Qt3DRender::QRenderCapture* m_capture; |
| 54 |
Qt3DRender::QRenderCaptureReply *m_reply; |
| 55 |
QMetaObject::Connection connection; |
| 56 |
QLabel *m_imageLabel; |
| 57 |
bool m_continuous; |
| 58 |
}; |
| 59 |
|
| 60 |
#endif |
| 61 |
|