QImage setPixel does not set alpha value
Hi,
I am trying to change the pixel value of image by using setPixel() method.
It is changing the RGB values successfully but not changing the Alpha value.
It always shows value 255.
The code is like this
QImage image = pixmap->tpImage();
int width = image.width();
int height = image.height();
for( i = 0 ; i < height; i++)
{
for( j = 0; j < width; j++ )
{
image.setPixel(j,i, QColor(0,0,0,0).rgb()) ;
}
}
Thanks in advance
~Sanjay
Re: QImage setPixel does not set alpha value
What's the image format (QImage::Format) of your image? Can it handle alpha values?
Re: QImage setPixel does not set alpha value
Quote:
Originally Posted by
sanjayshelke
image.setPixel(j,i, QColor(0,0,0,0).rgb()) ;
And maybe this should be
Code:
image.
setPixel(j,i,
QColor(0,
0,
0,
0).
rgba()) ;
Re: QImage setPixel does not set alpha value
hi,
Image format is QImage::Format_ARGB32 and i have tried with QColor(0,0,0,0).rgba() also.
But no effect.
Re: QImage setPixel does not set alpha value
try using:
QRgb qRgba ( int r, int g, int b, int a ) instead of qcolor.rgba()
Re: QImage setPixel does not set alpha value
Hi,
I want to correct my problem statement.
Thing is that whenever i am trying to change pixel value using setPixel(), it actually changes the pixel values.
e.g When i do;
image.setPixel(j,i, QColor(0,0,0,0).rgb()) ;
this makes the pixel transparent.
But after making it transparent if i ask to image what is rgba value at that position,
it shows me 0,0,0,255.
Actually it should give 0,0,0,0 rgba values.
I have written the code like this:
QImage image = pixmap->tpImage();
int width = image.width();
int height = image.height();
for( i = 0 ; i < height; i++)
{
for( j = 0; j < width; j++ )
{
image.setPixel(j,i, QColor(0,0,0,0).rgb()) ;
QColor clrAtPixel(imgPixmap.pixel(ptPos));
int r,g,b,a;
clrAtPixel.getRgb(&r,&g,&b,&a);
qDebug()<<r<<" "<<g<<" "<<b<<" "<<a;
}
}
I think setPixel is working fine and it is making the pixel transparent. ( I have seen that the image becomes transparent)
But after making it transparent when i ask for rgb values it gives 0,0,0,255.
The black color has same RGBA values as above.
Now my image is transparent but still it gives 0,0,0,255 rgba values.
Can anyone tell me whjat i m doing wrong.
Regards,
~Sanjay
Re: QImage setPixel does not set alpha value
Quote:
Originally Posted by
Lykurg
And maybe this should be
Code:
image.
setPixel(j,i,
QColor(0,
0,
0,
0).
rgba()) ;
Had you paid attention to this ? You are setting only rgb data, alpha is omitted hence !
Re: QImage setPixel does not set alpha value
Quote:
Originally Posted by
sanjayshelke
image.setPixel(j,i, QColor(0,0,0,0).rgb()) ;
QColor clrAtPixel(imgPixmap.pixel(ptPos));
You change the pixel at image but request the color at imgPixmap! So of course you won't get the correct alpha value. (and what is ptPos???)