BitmapImage from ByteArray/MemoryStream: Pixel format not supported

0

I am converting a BitmapImage from byte array, and it works fine, except with one specific .tif file. It gives an exception at EndInit():

The bitmap pixel format is unsupported. (Exception from HRESULT: 0x88982F80)

The code used to read the byte array to BitmapImage is:

public BitmapImage LoadImage(byte[] ImageData)       
    var image = new BitmapImage();
    using (var mem = new MemoryStream(imageData))
    {
        mem.Position = 0;
        image.BeginInit();
        image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
        image.CacheOption = BitmapCacheOption.OnLoad;
        image.UriSource = null;
        image.StreamSource = mem;
        image.EndInit(); //Exception here
    }
    image.Freeze();
    return image;
}

What does this mean? The image opens just fine in windows, so it is not corrupted or anything. Is there a way to convert the image to supported pixel format, before the EndInit?

c#
bitmapimage
pixelformat
asked on Stack Overflow May 7, 2018 by Juuseri

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0