Converting to transparent Image
hi,
I am loading a QImage which has two colors(white and black). I want to convert this image in such a way that all the white becomes transparent. i.e. resultant image should be transparent image wherever white color appears in source image.
Can anyone tell how can i accomplish this.
Thank you in advance
Re: Converting to transparent Image
You have to use :
Code:
QImage QImage::createAlphaMask ( Qt
::ImageConversionFlags flags
= Qt
::AutoColor ) const
And
Code:
QImage QImage::createMaskFromColor ( QRgb color, Qt
::MaskMode mode
= Qt
::MaskInColor ) const
Re: Converting to transparent Image
Thank you for the reply. and i already used this function and function is not returning transparent one.
Re: Converting to transparent Image
Re: Converting to transparent Image
How about replacing each pixel with white color with a pixel with Qt::transparent.
Code:
img.load("test.jpg");
for (int i = 0; i < img.height(); i++)
{
for (int j = 0; j < img.width(); j++)
{
if(img.pixel(j, i) == qRgba(255,255,255,255))
img.setPixel(j, i, Qt::transparent);//Or you can use qRgba(0,0,0,0) instead for trans
}
}
img.save("changed.png");//I dont remember that png can alpha channel or not.
Re: Converting to transparent Image
If you use a 8-bit image, you can simply manipulate the color table (QImage::setColorTable()).