PDA

View Full Version : QImage, PNG ad Transparency



Rebe
6th May 2011, 10:32
Hi!

I'm new to the forum and quite new to the Qt Programming.

I've a problem with QImage.
I need to draw an image (.png) with transparency.
I've serched and read a lot of thread on this forum, but I did'nt found any solution.

This is the code I used to load the image:


imm=QImage(53,48,QImage::Format_ARGB32_Premultipli ed);
immGL=QImage(53,48,QImage::Format_ARGB32_Premultip lied);

imm.load("image.png", "PNG");
immGL = QGLWidget::convertToGLFormat(imm);


This is the code to draw the image:



glRasterPos2i(x0,y0);
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, immGL.bits());


As a result, the image is drawn with all pixel that should be transparent converted to black.

Any solutions?

Thanks in advance,
Rebe

wysota
6th May 2011, 14:39
This is not the fault of QImage but rather of the way you use it. Either your image.png doesn't contain transparency or information about it is lost in OpenGL. And first two lines of your first code snippet can be discarded as lines #4 and #5 respectively will overwrite the objects created earlier.

Rebe
6th May 2011, 15:41
Ok, thanks.
I will check OpenGL options.

GortiZ
14th May 2014, 09:52
Hi, I've the same issue, did you solved it?
What did you did?

Thanks,
GortiZ

testqt
30th May 2014, 08:26
hi i am very new to QT please help me on Immage reading(raw immage) from QT using QgraphisScreen as base calss and derived method from QGLWidget ... if provide me sample code or URL Thanks in advance ....

wysota
30th May 2014, 08:41
QImage img("path/to/image");