Creating WPF BitmapImage from MemoryStream png, gif

后端 未结 2 1282
星月不相逢
星月不相逢 2020-11-27 04:45

I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downlo

2条回答
  •  孤城傲影
    2020-11-27 05:38

    I'm using this code:

    public static BitmapImage GetBitmapImage(byte[] imageBytes)
    {
       var bitmapImage = new BitmapImage();
       bitmapImage.BeginInit();
       bitmapImage.StreamSource = new MemoryStream(imageBytes);
       bitmapImage.EndInit();
       return bitmapImage;
    }
    

    May be you should delete this line:

    bi.DecodePixelWidth = 30;
    

提交回复
热议问题