How to control the quality/filesize of images copied to the clipboard?
-
You can't, QImage is an uncompressed hardware independent representation of the image that allows direct access to pixel data while QPixmap is an off-screen image representation that you can be used as a paint device so it's hardware dependent.
If you want small images in your PowerPoint document you have to start with the original image and make them lighter.
@SGaist said in How to control the quality/filesize of images copied to the clipboard?:
If you want small images in your PowerPoint document you have to start with the original image and make them lighter.
Yes, but the question has been, how do I make the original image lighter and reflect this when copied to the clipboard?
-
@SGaist said in How to control the quality/filesize of images copied to the clipboard?:
If you want small images in your PowerPoint document you have to start with the original image and make them lighter.
Yes, but the question has been, how do I make the original image lighter and reflect this when copied to the clipboard?
@btse
and what about the way i already suggested?!QPixmap pixmap; QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter buffer.close(); QMimeData *mimeData = new QMimeData; mimeData->setData("image/png", bytes); QApplication::clipboard()->setMimeData(mimeData);This should definitely work, even when the your used clipboard inspector doesn't display it correctly.
-
@btse
and what about the way i already suggested?!QPixmap pixmap; QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter buffer.close(); QMimeData *mimeData = new QMimeData; mimeData->setData("image/png", bytes); QApplication::clipboard()->setMimeData(mimeData);This should definitely work, even when the your used clipboard inspector doesn't display it correctly.
@raven-worx said in How to control the quality/filesize of images copied to the clipboard?:
@btse
and what about the way i already suggested?!QPixmap pixmap; QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter buffer.close(); QMimeData *mimeData = new QMimeData; mimeData->setData("image/png", bytes); QApplication::clipboard()->setMimeData(mimeData);This should definitely work, even when the your used clipboard inspector doesn't display it correctly.
It simply doesn't work, not sure what else to tell you. I tried pasting it to many different applications, none of them recognize the clipboard's contents. Have you been able to get this example to work? I've been testing on Mac OS 10.11.6 with Qt 4.8.7.2.
-
Two years too late, but as I was having the exact same issue it might help a lost soul in the future.
A workaround for this is to save a temporary image and copy to clipboard the url to the file. This is recognized in most software on Mac (PPTX, Keynote included) and should work on Windows.
void ToClipboard(const QPixmap& pixmap) { QString filename = "/tmp/screenshot.png"; pixmap.save(filename); QList<QUrl> urls; urls << QUrl(filename); QMimeData* outputMime = new QMimeData; outputMime->setUrls(urls); qApp->clipboard()->setMimeData(outputMime); }Take care of the typical caveats when writing to disk from an application, but for most applications that might need this (user-generated, user-controlled operations) this is an ok workaround.