Unsolved Changing Pixmap Color transition (Saturation, hue..)
-
Hi everyone ,
I am exploring on how to change the pixmap color but to no avail. I tried looking around and came across an obsolete class QPixmapFilter. It is no longer in used so I am wondering what other source should I look out for. My intention is to change the color of existing picture (Say a picture of a blue laptop). I want to change its color to red. I would like to make sure it change its color from blue to red in a smooth transition.
Thank you and look forward for reply and discussions.
-
QPixmap.toImage()
...define smooth transition. are you talking about animated changes or gradients? QPixmap is not meant to be edited. You copy it to a QImage and then you have access to the raw pixel data.
-
Hi Kent-Dorfman,
Thanks for the reply. Smooth color transition. I believe it would be the gradients from red to blue. So that means I must use QImage? The reason why I use QPixmap is because I wanted to put it under QLabel.
-
I think you misunderstand. you must copy the image to QImage to do the pixel manipulation, but then you can retype it back to any other compatible format you desire. You just cannot edit it in QPixmap format.
-
Hi Kent-Dorfman,
I managed to change to QImage and do the pixel manipulation. I used loops to do the manipulation pixel by pixel. I felt that it is inefficient. Is there anyway it can be more efficient? Or using loops is the only way to achieve this?
What was done was, Using Qt logo as the QImage, I managed to change its green to red. but it go from left to right, from up to down. (Using loops).
-
-
Thank you for replying. Hmmm, i noted your suggestion but how do I exactly use them ? I look at the documentation but have no idea how to start using scanLine or bits.
-
here is an example:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QImage img(400,400,QImage::Format_RGB888); quint32 white(0xFFFFFFFF); quint32 black(0x00000000); for(uint i(0), h(img.height()); i < h; i++) { uchar *index = img.scanLine(i); for(uint j(0), bbl(img.bytesPerLine()); j < bbl; j+=3){ memcpy(index+j, (i % 2) ? &black : &white, 3); } } QLabel lbl; lbl.setPixmap(QPixmap::fromImage(img)); lbl.show(); return a.exec(); }
-
@J.Hilk thank you J.Hilk. I will work/play into it and let you know by the end of this weekend.