[Qt-interest] QClipboard: image alpha channel support?
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Mon Dec 27 14:54:47 CET 2010
Hi,
On Windows XP, Qt 4.7.1 (binary MinGW distribution), I have a QImage with alpha channel (it is saved fine as PNG and checked in Gimp for proper alpha values) and I want to put this image into the system clipboard:
QClipboard *clipboard =QApplication::clipboard();
QImage image(w, h, QImage::Format_ARGB32);
...
QMimeData *mimeData = new QMimeData();
mimeData->setImageData(image);
clipboard->setMimeData(mimeData);
when I paste this image into e.g. OpenOffice Draw or MS PowerPoint the background (which is supposed to be fully transparent) is black and everything is fully opaque. It looks like there is a cut-off done like
alpha < 128 -> black
alpha >=128 -> opaque
or in other words: "alpha gradients become a 0, 1 bitmap mask", or so it seems.
A little Google research brought up similar questions like http://stackoverflow.com/questions/1420640/howe-can-i-retrieve-the-correct-image-with-correct-alpha-channel-from-qmimedata (which actually deals with pasting /into/ a Qt application), but I did not find an answer.
But inspired by some code I found I tried (instead of mimeData->setImageData):
QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG");
buffer.close();
mimeData->setData("image/png", data);
that is, store the data as PNG. But this does not paste any data, neither in OpenOffice Draw nor MS PowerPoint. Also note that in either case I was able to paste into The GIMP: "No data available for pasting" or so (but see my follow-up posting, separate question).
Can anyone confirm whether (on Windows) alpha channels in the clipboard are supported at all? The fact that I found no application which actually copies the alpha value makes me thing that on Windows this is simply not possible? Or is it a question of setting the proper MIME type (which?) in QMimeData#setData?
E.g.
- Copy/paste from Gimp -> OpenOffice: the checkered "alpha background" is used
- Copy a PNG with alpha from OpenOffice -> PowerPoint: the background is simply "white" (but fully opaque)
Thanks,
Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list