Skip to content

Commit

Permalink
Create snapshot image using grabWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 23, 2024
1 parent c82bdc3 commit 873c446
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Fwk/AppFwk/cafViewer/cafViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@
#include "cvfqtUtils.h"

#include <QDebug>
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QInputEvent>
#include <QPainter>
#include <QScreen>
#include <QWindow>

#include <cmath>

Expand Down Expand Up @@ -1241,15 +1244,16 @@ QImage caf::Viewer::snapshotImage()
}
else
{
// Code moved from RimView::snapshotWindowContent()
QScreen* screen = QGuiApplication::primaryScreen();

GLint currentReadBuffer;
glGetIntegerv( GL_READ_BUFFER, &currentReadBuffer );
if ( const QWindow* window = windowHandle() ) screen = window->screen();

glReadBuffer( GL_FRONT );
image = QImage(); //this->grabFrameBuffer();

glReadBuffer( currentReadBuffer );
if ( screen )
{
auto windowId = winId();
auto originalPixmap = screen->grabWindow( windowId );
image = originalPixmap.toImage();
}
}

return image;
Expand Down

0 comments on commit 873c446

Please sign in to comment.