View Full Version : Accessing alpha channel of QImage directly

19th March 2009, 15:27
Hi. I'm trying to create a QImage and set the alpha channel to some value on a per-pixel basis. setAlphaChannel is no good because it sets the whole image at once.

Ideally, I'd have brushes treat the alpha component as non-special, i.e. the operation wouldn't be
pixel = (old_r,old_g,old_b)*(1-alpha) + (new_r,new_g,new_b)*alpha
but instead
pixel = (new_r, new_g, new_b, new_a)
or even
pixel = (old_r,old_g,old_b,old_a)*(1-beta) + (new_r,new_g,new_b,new_a)*beta

In the short term, however, setting pixels' alphas individually would be acceptable.

19th March 2009, 15:35
And what is wrong with using QImage::setPixel()?

19th March 2009, 15:41
setPixel refers to RGB, not RGBA

Oh, and I forgot to say, the long term solution for me is to paint alpha channels directly via a brush, but this refers to QPainters and not QImages! I'm doing it per-pixel in a QImage at the moment as a short term hack

Thinking about it, what I'm after is a kind of "eraser" brush, photoshop-style, and I want this to be at the level of a QBrush, not pixel hacking.

19th March 2009, 16:24
setPixel refers to RGB, not RGBA

No, it referrs to QRgb which may also contain the alpha value.