Qimage Indexed8
In my project I need to convert an image with many colors to one that only uses any of the 144 predetermined colors I set in a custom colorTable.
Here is my code:
I would expect convImage to only contain colors that exist in the colorTable I created, however it seems to completely ignore the table I set and instead creates it's own unique table with 256 max colors.
I have started learning Qt and is trying to make a simple video Player which will load the video and will play it. It worked perfectly fine. Now added thresholding functionality to it.
I could index everything myself by looping through every pixel and find a way to accurately select a color from the colorTable, but I am wondering if I am just using the colorTable wrong. I couldn't find anything in the documentation that explains why a new table is being created.
Thanks for your time.
mrg95Qimage Indexed 8
mrg95Qimage Grayscale Format_indexed8

1 Answer
Well, ask yourself: how should the convertToFormat()
call on scaledImage
possibly know about the colortable you applied to convImage
? It doesn't know anything about the convImage
on the left-hand-side.
- QImage QImage:: createAlphaMask ( Qt::ImageConversionFlags flags = Qt::AutoColor) const. Returns a null image if the image's format is QImage::FormatRGB32. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags, and controls the conversion process. Passing 0 for flags sets all the default options.
- QImage also provide the scanLine function which returns a pointer to the pixel data at the scanline with the given index, and the bits function which returns a pointer to the first pixel data (this is equivalent to scanLine(0)). Image Formats. Each pixel stored in a QImage is represented by an integer.
Fortunately, there's an overload of convertToFormat
that takes a colortable and should do the job: