From 873c44611044916d65b4ddb5e2ca64cebebcf303 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 23 Jan 2024 13:20:51 +0100 Subject: [PATCH] Create snapshot image using grabWindow --- Fwk/AppFwk/cafViewer/cafViewer.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Fwk/AppFwk/cafViewer/cafViewer.cpp b/Fwk/AppFwk/cafViewer/cafViewer.cpp index 8f219362904..a08012bad35 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.cpp +++ b/Fwk/AppFwk/cafViewer/cafViewer.cpp @@ -74,9 +74,12 @@ #include "cvfqtUtils.h" #include +#include #include #include #include +#include +#include #include @@ -1241,15 +1244,16 @@ QImage caf::Viewer::snapshotImage() } else { - // Code moved from RimView::snapshotWindowContent() + QScreen* screen = QGuiApplication::primaryScreen(); - GLint currentReadBuffer; - glGetIntegerv( GL_READ_BUFFER, ¤tReadBuffer ); + 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;