Qimage Indexed8

18.08.2019
Qimage Indexed8 5,0/5 3991 reviews
Active3 years, 6 months ago

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.

mrg95

Qimage Indexed 8

mrg95

Qimage Grayscale Format_indexed8

7062 gold badges24 silver badges55 bronze badges
Qimage 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:

ThorngardSOThorngardSO
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged c++qtqimagecolor-space or ask your own question.