PDA

View Full Version : is there a simple and quick way to convert color images to gray image?



elflord
6th March 2009, 13:55
something like colorimg.togray()

i didn't find in QImage class

thx

JimDaniel
6th March 2009, 14:43
Not that I'm aware of. What you will probably need to do is call bits(), which returns a uchar * to the first bit, and then iterate over them all, applying some rgb->grayscale algorithm to each bit. A quick google search found a few simple algorithms, so it shouldn't be too difficult.

aamer4yu
6th March 2009, 14:58
Not sure if there is any direct function...
but you can iterate over the image pixels and use QColor::qGray to convert the rgb into gray scale :)

JimDaniel
6th March 2009, 15:11
Iterating over QImage pixels() and converting with QColor would certainly be easier, but I wonder what the performance would be like. It seems like it would be significantly slower than accessing the bits directly, but I don't know if there's any basis for that. I am interested now. Maybe this weekend I will have a chance to try it out myself.