[Qt-interest] how to build a grayscale QImage

Dan Milburn danmilburn at clara.co.uk
Mon Feb 22 11:11:17 CET 2010


> But no QImage constructor take a data pointer and a color table together.
> Besides, how can i create a grayscale color table? 
> should i set a for loop from 1 to 256 and set the current entry of color 
> table with the current index of the loop?
> I get confused with the Format enum. It just supports mono(0-1) and 8bit 
> indexed; why not a "grayscale" option to make things easier? 
> 
Hi,

Not that I speak for Nokia, but they can't cover every possible image 
format, and there probably isn't a great deal of demand for grayscale 
images these days.

Besides, generating a grayscale color table is really not difficult to do:

QVector<QRgb> table( 256 );
for( int i = 0; i < 256; ++i )
{
   table[i] = qRgb( i, i, i );
}

None of the QImage constructors take this, but you can set it on the 
image immediately afterwards.

Dan



More information about the Qt-interest-old mailing list