PDA

View Full Version : QPixmap(image) to transparent HBITMAP



ascii
26th February 2009, 14:33
i read about this problem some solution but don't work.

shortly i want to do this;

QPixmap pix;
pix.load(":XXX/Resources/r1.png"); // transparent png file
pix.toWinHBITMAP(QPixmap::PremultipliedAlpha); // but this is not transparent

this is not transparent. it has black background.

if somebody help me or give me a link about that i will be very happy.
:confused:
thank you...

^NyAw^
26th February 2009, 15:01
Hi,

The QPixmap doc says:

The HBITMAP is treated as having a alpha channel and premultiplied colors. This is preferred if the HBITMAP is accessed through the AlphaBlend() GDI function.

So, the HBITMAP has alpha channel but it don't say that converts the pixmap to a transparent HBITMAP.
When you get the HBITMAP you need to change the alpha channel value of the pixels to obtain the desired image.

ascii
28th February 2009, 09:08
Can you give me an example?

^NyAw^
1st March 2009, 13:24
Hi,

Has the orginal image a black background?

ascii
1st March 2009, 14:07
No, it has transparent background.

^NyAw^
1st March 2009, 17:27
Hi,

Can you get alpha values from a converted pixel? Which values you get it?

ascii
2nd March 2009, 06:26
hasAlpha() = 1
hasAlphaChannel() = 1

alphaChannel() is return only where is transparent pixels with black background.

^NyAw^
2nd March 2009, 09:03
Hi,

And wich value of the alpha channel are you getting on a background pixel?
255 -> full color
0 -> transparency (don't remember if 255=full color and 0=transparency or inverse).