Could you try with a different file? For example the one attached. The application won't work for 8 bit (indexed) images like qt-logo.
Could you try with a different file? For example the one attached. The application won't work for 8 bit (indexed) images like qt-logo.
sincnarf (6th July 2007)
Thank you both wysota and jacek! wysota's sample program worked for the attached image kdmconfig.png!
Just as I thought I need to know what valid image conversions I should use.
@wysota, what do i need to do in order to pattern other images to the properties of kdmconfig.png. Can you give me the exact properties of that attached kdmconfig? I opened it in Adobe Photoshop CS2 and I saw that the image's mode is "RGB Color", "8 bits / channel", and bit depth = "32". What other pertinent information am I missing?
@jacek, in QImage::setColorTable ( const QVector<QRgb> colors ), what is "QVector<QRgb> colors"? Is that where I set my gray color?
Separate question: By the way how much maximum colors can QImage support? Is it 256? Thanks in advance for all the advice! Thank God I saw QtCentre.org!
They should be True or Full Color, not indexed. With indexed images (ones that have the color lookup table) you just need to change the contents of the lookup table without touching actual pixels.
kdmconfig.png: PNG image data, 128 x 128, 8-bit/color RGBA, non-interlacedCan you give me the exact properties of that attached kdmconfig?
Yes, for indexed images.in QImage::setColorTable ( const QVector<QRgb> colors ), what is "QVector<QRgb> colors"? Is that where I set my gray color?
16777216 (2^24). Multiplied by 256 if you also count different alpha values which then gives 4294967296 (4G) colours.Separate question: By the way how much maximum colors can QImage support? Is it 256?
sincnarf (4th October 2007)
hmmm. definitely got the "non-interlaced" advice. Is this how you use setColorTable method?
Qt Code:
int gray = 0; int pixel = 0; image.setNumColors(256); QVector<QRgb> colorTable(256); for (x= 0; x < image.width(); x++){ for (y = 0; y < image.height(); y++){ pixel = image.pixel(x, y); gray = qGray(pixel); colorTable.append(qRgb(gray, gray, gray)); } } image.setColorTable(colorTable);To copy to clipboard, switch view to plain text mode
No, get the original colour table using QImage::colorTable(), replace all of the entries with grayscale equivalents and set the new colour table using QImage::setColorTable(), but only if the image has a colour table (i.e. QImage::numColors() is greater than 0).
sincnarf (4th October 2007)
Bookmarks