Search code examples
.net-coreimagesharp

Create image from palette indexes with ImageSharp


I have an array of bytes that represents the palette indexes of the pixels of an image, and I'm trying to convert this to an image with ImageSharp, so I can save it later as PNG, but I can't seem to find how, can anyone give me an idea on where to look? The palette is not important, I just need N different colors.


Solution

  • ImageSharp images represent the expanded pixel buffer, not references to color palettes. If you have the original palette use it to create the input buffer of actual pixel data. A byte array as described is not, in real terms a fully decoded image.

    Reducing a color set to a maximum amount is a question of quantization. There are methods that allow you to do this as well as encoding options that allow saving images in indexed formats.