I'm using Image Sharp in an ASP.Net Core project and now need to prepare PNG images for a device that can only handle 2 colour indexed PNG images.
If I use the following code, then the images are saved as palleted 2 colour images, but the result is corrupt, looks to me that there is no pixel packing happening.
private void ConvertToMonoPng(Stream stream, string fileName)
{
Image<Rgba32> image = Image.Load(fileName);
var enc = new PngEncoder();
enc.CompressionLevel = PngCompressionLevel.Level9;
enc.ColorType = PngColorType.Palette;
enc.BitDepth = PngBitDepth.Bit1;
image.Save(stream, enc);
image.Dispose();
}
The results are:
Source Image
Output Image
I know that the ImageSharp library doesn't currently support sub-byte packed pixels in memory, but since there does seem to be some support in the PNGEncoder, I'm hoping that saving monochrome PNG's is supported and I'm just doing something wrong.