[Qt-interest] how to build a grayscale QImage
Boudewijn Rempt
boud at valdyas.org
Mon Feb 22 11:18:12 CET 2010
On Mon, 22 Feb 2010, Dan Milburn wrote:
> > 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.
You'd be surprised -- grayscale images are used a lot, for instance
for masking. When working on krita, we ran into this issue only last week:
we wanted to use QImage, but since you cannot paint on an indexed image,
we had to cook up our own solution.
>
> 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.
The big problem with indexed images is that you cannot use QPainter
on them.
Boudewijn
More information about the Qt-interest-old
mailing list