[Qt-interest] QImage and ARGB32_Premultiplied

noam.rosenthal at nokia.com noam.rosenthal at nokia.com
Sun Jan 30 04:32:09 CET 2011


________________________________________
From: qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com [qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com] On Behalf Of ext Joshua Grauman [jnfo-c at grauman.com]
Sent: Saturday, January 29, 2011 4:02 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QImage and ARGB32_Premultiplied


> Thanks. That's what I figured, but I guess my real question then is how to
> set an alpha channel for a ARGB32_Premultiplied QImage?

You should check out composition modes (http://doc.qt.nokia.com/4.7/qpainter.html#composition-modes). They allow you to modify a particular color element of the image you're drawing to, and they're generally optimized.
In your case you set the painter's composition mode to QPainter::CompositionMode_DestinationIn which would modify only the alpha-channel of the target image, and then fill it with a solid-color rect that has your alpha value.


  qreal wantedAlpha = 0.5;
  QPainter painter(image);
  painter.setCompositionMode(QPainter::CompositionMode_DestionationIn);
  painter.fillRect(QRect(0, 0, image2.width(), image2.height()), QColor(0, 0, 0, wantedAlpha * 256);



More information about the Qt-interest-old mailing list