Home > OS >  How can I convert a PNG Image to a 1Bpp using SkiaSharp
How can I convert a PNG Image to a 1Bpp using SkiaSharp

Time:01-24

How can I convert a PNG Image to a 1Bpp using SkiaSharp. I am currently using the SkiaSharp to do all the image processing for my .NET applications/services, and I have not been able to find an in-built way to encode an image from a SKCanvas or SKData to a 1bpp image format, I saw that Bmp & wbmp are available but they both return null in the following example:

byte[] imageBytes = *PNG Image Byte Array*
SKImage.FromEncodedData(imageBytes).Encode(SKEncodedImageFormat.Bmp, 100).ToArray();
SKImage.FromEncodedData(imageBytes).Encode(SKEncodedImageFormat.Wbmp, 100).ToArray();

Any ideas on how to accomplish this without doing a lot of custom code? Any help is most appreciated.

CodePudding user response:

In the SkiaSharp, only three of these file formats (Jpeg, Png, and Webp) are actually supported by SkiaSharp. For all the other formats, the Encode method writes nothing into the stream and the resultant byte array is null. So this can not convert a PNG Image to a 1Bpp by using SkiaSharp.

  • Related