PDA

View Full Version : read file in b/w mode



eric
11th December 2007, 17:56
Hello all!

I need to load an image file (which is true color) in grayscale format. So, I need to convert the file during loading somehow. I read that there are flags for that. I am not sure (even after reading the assistant) how to do it.
How close am I :)?



myImage.load(filename,Qt::MonoOnly);


thanks

wysota
11th December 2007, 19:59
Faar faaaar away :)

Load the image as usual and then either use QImage::convertToFormat() or iterate over its pixels and change their value to gray using qGray() and QImage::setPixel().

eric
11th December 2007, 20:18
:) OK you got me a bit closer, thanks. But I am still confused about what the "Format" really means and what the syntax is.

These don't work:




//myFile is a QPixmap

myFile.convertToFormat(3, Qt::MonoOnly);

//or

myFile.convertToFormat(Format_Indexed8, Qt::MonoOnly);


Compiler says: 'class QPixmap has no member named convertToFormat'

wysota
11th December 2007, 20:35
The compiler is right. You should be using QImage.

The format is the way image data is stored internally - I doubt converting to indexed format will make you image gray - you'd have to change its palette to do that afterwards. MonoOnly would probably make you image black and white instead of grayscale. So you either need to convert to an indexed mode and then readjust the colour map (palette) or iterate over pixels and convert each of them to gray.