Changed Qt GUI screen shot function to use Qt image capture of the actual video viewport so that a higher resolution image that has the effects of the aspect ratio and scaler video selections in it.

This commit is contained in:
mjbudd77 2021-05-14 21:30:28 -04:00
parent 2f37a95e75
commit 8f245c9332
2 changed files with 57 additions and 2 deletions

View File

@ -31,6 +31,10 @@
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <QPixmap>
#include <QWindow>
#include <QScreen>
#include <QHeaderView>
#include <QFileDialog>
#include <QMessageBox>
@ -824,7 +828,7 @@ void consoleWin_t::createMainMenu(void)
//scrShotAct->setShortcut( QKeySequence(tr("F12")));
scrShotAct->setStatusTip(tr("Screenshot"));
scrShotAct->setIcon( QIcon(":icons/camera.png") );
connect(scrShotAct, SIGNAL(triggered()), this, SLOT(takeScreenShot()));
connect(scrShotAct, SIGNAL(triggered()), this, SLOT(prepareScreenShot(void)));
fileMenu->addAction(scrShotAct);
@ -2340,10 +2344,60 @@ void consoleWin_t::mainMenuClose(void)
}
}
void consoleWin_t::prepareScreenShot(void)
{
// Set a timer single shot to take the screen shot. This gives time
// for the GUI to remove the menu from view before taking the image.
QTimer::singleShot( 100, Qt::CoarseTimer, this, SLOT(takeScreenShot(void)) );
}
//void consoleWin_t::takeScreenShot(void)
//{
// fceuWrapperLock();
// FCEUI_SaveSnapshot();
// fceuWrapperUnLock();
//}
void consoleWin_t::takeScreenShot(void)
{
int u=0;
QPixmap image;
QScreen *screen = QGuiApplication::primaryScreen();
if (const QWindow *window = windowHandle())
{
screen = window->screen();
}
if (screen == NULL)
{
return;
}
fceuWrapperLock();
FCEUI_SaveSnapshot();
if ( viewport_GL )
{
image = screen->grabWindow( viewport_GL->winId() );
}
else if ( viewport_SDL )
{
image = screen->grabWindow( viewport_SDL->winId() );
}
for (u = 0; u < 99999; ++u)
{
FILE *pp = FCEUD_UTF8fopen( FCEU_MakeFName(FCEUMKF_SNAP,u,"png").c_str(), "rb");
if (pp == NULL)
{
break;
}
fclose(pp);
}
image.save( tr( FCEU_MakeFName(FCEUMKF_SNAP,u,"png").c_str() ), "png" );
fceuWrapperUnLock();
}

View File

@ -291,6 +291,7 @@ class consoleWin_t : public QMainWindow
void decrementState(void);
void loadLua(void);
void takeScreenShot(void);
void prepareScreenShot(void);
void powerConsoleCB(void);
void consoleHardReset(void);
void consoleSoftReset(void);