View Full Version : Converting to transparent Image
navi1084
28th August 2009, 11:50
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
yogeshgokul
28th August 2009, 11:56
You have to use :
QImage QImage::createAlphaMask ( Qt::ImageConversionFlags flags = Qt::AutoColor ) const
And
QImage QImage::createMaskFromColor ( QRgb color, Qt::MaskMode mode = Qt::MaskInColor ) const
navi1084
28th August 2009, 12:04
Thank you for the reply. and i already used this function and function is not returning transparent one.
yogeshgokul
28th August 2009, 12:13
Can you show the code.
yogeshgokul
28th August 2009, 12:44
How about replacing each pixel with white color with a pixel with Qt::transparent.
QImage img;
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.
Lykurg
28th August 2009, 13:25
If you use a 8-bit image, you can simply manipulate the color table (QImage::setColorTable()).
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.