PDA

View Full Version : QImage Transparency



sapali
26th July 2011, 23:06
Hi,


I am trying to clip an image with a curve by setting the corresponding to-be-clipped pixels to transparent. I am using qt3 and the code follows for transparency does not work.


image.setAlphaBuffer(TRUE);
QColor trans(Qt::color0.rgb());
// QRgb mycol = qRgba ( 255, 255, 255,0 );
// trans.setRgb(mycol);
for (int i = 0; i < img_height; i++){
for (int j = 0; j < img_width; j++){
if (tempimg[i][j] == 0)
image.setPixel(i,j, trans.rgb());
}
}


Any ideas what I'm doing wrong?

Thank you,
Sapal

high_flyer
27th July 2011, 15:28
Any ideas what I'm doing wrong?
You are not setting the alpha channel.
Use rgba() not rgb().

sapali
28th July 2011, 05:52
The problem is that I'm using qt3 and QColor takes only 3 arguments(r,g,b) and the thing is the setPixel in QImage only uses r,g,b. I really don't know how to set and check the alpha value for the pixel in qt3!! any suggestions?

Thank you for your help

SixDegrees
28th July 2011, 07:52
Have you tried using the documentation (http://doc.qt.nokia.com/3.3/)?

Qt 3's support for transparency is only fair. You should switch to Qt 4, although you can do what you're after in Qt 3.

You might try setting the alpha value to an intermediate value, like 125, to make sure transparency is working in the first place.

high_flyer
28th July 2011, 09:34
The problem is that I'm using qt3 and QColor takes only 3 arguments(r,g,b) and the thing is the setPixel in QImage only uses r,g,b.
Not true.
http://doc.qt.nokia.com/3.3/qimage.html#setPixel
And
http://doc.qt.nokia.com/3.3/qcolor.html#qRgba