[Qt-interest] QImage and ARGB32_Premultiplied
Joshua Grauman
jnfo-c at grauman.com
Sun Jan 30 01:02:35 CET 2011
> On Saturday, 29 de January de 2011 14:41:14 Joshua Grauman wrote:
>> 1) If I have one QImage that is ARGB32_Premultiplied and one that is
>> ARGB32, if I assign one into the other (ie. image1=image2), will QImage do
>> the conversion for me?
>
> No. The two images will be equal (QImage is implicitly shared). They will be
> both of the same format, with the exact same pixel content.
>
>> 3) Seeing that setAlphaChannel() is deprecated, what is the fastest way to
>> set the alpha channel to a single value for an entire image (for an
>> ARGB32_Premultiplied QImage). Do I have to iterate over each pixel and
>> calculate/set the premultiplied values?
>
> Probably by blending with another image that has an alpha channel. Iterating
> would be slower than doing the blend.
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?
I'm thinking something like this:
QImage image1(size, QImage::Format_ARGB32_Premultiplied);
QImage image2(size, QImage::Format_ARGB32_Premultiplied);
//load/draw image1 and image2
QPainter p1(&image1);
//Currently image2 has no alpha channel. I want to set the alpha channel
//of every pixel to a fade value, say 50% = 128
//what would be the best way to set the alpha channel of every pixel,
//given that it is an ARGB32_Premultiplied QImage
p1.drawImage(0,0,image2);
Josh
More information about the Qt-interest-old
mailing list