Decoding Bitmap always returns null.

I have a bitmap file that I am getting from an azure service as a byte array. I know the bitmap is correct because I can convert the byte[] into a MemoryStream and then into a System.Drawing.Bitmap. I have tried getting the bitmap in SkiaSharp 2 different ways and both times, the .Decode() method returns null.

byte[] imageBytes = OrderFileService.Get(orderId);

using (var bitmap = SKBitmap.Decode(imageBytes))
    {
    var w = bitmap.Width;
        var h = bitmap.Height;
}

using (var memoryStream = new MemoryStream(imageBytes))
    using (var stream = new SKManagedStream(memoryStream))
    using (var bitmap = SKBitmap.Decode(stream))
    {
         var w = bitmap.Width;
         var h = bitmap.Height;
    }

In both cases SKBitmap.Decode() returns null. Is there something additional I need to do? I think the image I am using has an indexed pixel format. Does that matter? The file is an Exported Bitmap from CorelDraw.

Tagged:
Sign In or Register to comment.