How to convert Byte[] to BitmapImage

前端 未结 4 1934
傲寒
傲寒 2020-12-10 02:32

I need help, I have this method to get a BitmapImage from a Byte[]

public BitmapSource ByteToBitmapSource(byte[] image)
{
    BitmapImage imageSource = new B         


        
4条回答
  •  一整个雨季
    2020-12-10 02:57

    Set Image.Source to a byte array property in XAML.

    
    

    If you really want you can do this in code-behind:

    public void DecodePhoto(byte[] byteVal)
    {
      BitmapImage myBitmapImage = new BitmapImage();
      myBitmapImage.BeginInit();
      myBitmapImage.StreamSource = new MemoryStream(byteVal);
      myBitmapImage.DecodePixelWidth = 200;
      myBitmapImage.EndInit();
      MyImage.Source = myBitmapImage;
    }
    

提交回复
热议问题