From 8f058f98f3ba288d95f65ae22f9945a44c4c0146 Mon Sep 17 00:00:00 2001 From: Sonu Lohani Date: Fri, 29 Jan 2021 19:17:48 +0530 Subject: [PATCH] JPG for clipboard --- src/utils/screenshotsaver.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 95f8d3d3..8f26795f 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -21,6 +21,7 @@ #include "src/utils/filenamehandler.h" #include "src/utils/systemnotification.h" #include +#include #include #include #include @@ -51,8 +52,22 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture) // Otherwise only save to clipboard else { SystemNotification().sendMessage( - QObject::tr("Capture saved to clipboard")); - QApplication::clipboard()->setPixmap(capture); + QObject::tr("Capture saved to clipboard")); + + QByteArray array; + QBuffer buffer{&array}; + QImageWriter imageWriter{&buffer, "JPG"}; + imageWriter.write(capture.toImage()); + + QPixmap jpgPixmap; + bool isLoaded = jpgPixmap.loadFromData( + reinterpret_cast(array.data()), array.size(), "JPG"); + if(isLoaded) { + QApplication::clipboard()->setPixmap(jpgPixmap); + } + else { + QApplication::clipboard()->setPixmap(capture); + } } }