Load a byte[] into an Image at Runtime

后端 未结 4 1362
醉话见心
醉话见心 2021-01-11 13:09

I have a byte[] that is represented by an Image. I am downloading this Image via a WebClient. When the WebClient

4条回答
  •  猫巷女王i
    2021-01-11 13:24

    One way that I figured out how to do it so that it was both fast and thread safe was the following:

     var imgBytes = value as byte[];
     if (imgBytes == null)
      return null;
     using (var stream = new MemoryStream(imgBytes))
       return BitmapFrame.Create(stream,BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
    

    I threw that into a converter for my WPF application after running the images as Varbinary from the DB.

提交回复
热议问题