QImage and Qt::transparent
hi
i want to paint on an image.How to make the image background as transparent.
the following code can change the background color of the image .
Code:
image.fill(colormap.pixel(Qt::green));
but it fails to make the background transparent even when the code is changed to
Code:
image.fill(colormap.pixel(Qt::transparent));
i wnt to paint on aQImage rather than QPixmap is because, i am painting in a multithreaded program.
how to make the background of a QImage as transparent.
Re: QImage and Qt::transparent
try:
Code:
image.fill(qRgba(0, 0, 0, 255));
and make sure the QImage depth is 32 bits.
Re: QImage and Qt::transparent
The image depth is 32 but had not worked:(.
Code:
qDebug()<<"depth "<<image.depth(); //prints 32
image.fill(qRgba(0, 0, 0, 255));
Re: QImage and Qt::transparent
how do you test if the image is transparent or not?
Re: QImage and Qt::transparent
after the above code
//code in worker thread
Code:
painter.save();
//painting is performed
painter.restore();
//code in main gui thread.
Code:
pixmap
=QPixmap::fromImage(worker_thread.
image);
//image is converted to pixmapupdate();//inside the paintevent the pixmap is painted on to widget.
i get black as the background color.
But if any color is given(instead of Qt::transparent) such as green then green color is the background color
Code:
image.fill(colormap.pixel(Qt::green));
Re: QImage and Qt::transparent
what are u trying to achieve ? I am still not clear abt it .
Are u making an application by which user can draw over a area, with an image in the bcground ??
Sort of image editing application ? am i getting u right ?
Re: QImage and Qt::transparent
Quote:
Sort of image editing application ?
no
A image is constructed(made) by painting on a QImage object with QPainter .Before painting on the image the image background should be set to transparent.
Re: QImage and Qt::transparent
ohh oh !!!
I guess i caught the mistake...
Quote:
image.fill(qRgba(0, 0, 0, 255)); should be
image.fill(qRgba(0, 0, 0, 0));
255 specifies NO OPACITY !!
Hope this will solve the prob ;)
Re: QImage and Qt::transparent
thanks for reply
but it did not work:(
Re: QImage and Qt::transparent
QImage::Format_RGB32 doesn't support transparency. Use QImage::Format_ARGB32
Re: QImage and Qt::transparent
thanks wysota
constructing the image with QImage::Format_ARGB32 and then using image.fill(qRgba(0,0,0,0));
makes the image transparent
Re: QImage and Qt::transparent
Hi, sorry to bump this thread, but is it possible to make a QIcon out of an image where some parts are transparent, and then fill the opaque parts of the icon with some background color?