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.
-
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).
-
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(); }