How to convert from type Image to type BitmapImage?

后端 未结 3 1729
北海茫月
北海茫月 2020-12-31 23:55

Does anyone know how to create a BitmapImage from an Image? Here is the code that I\'m working with:

MemoryStream memStream = new MemoryStream(bytes);
Image          


        
3条回答
  •  耶瑟儿~
    2021-01-01 00:05

    Bitmap      img   = (Bitmap) Image.FromStream(memStream);
    BitmapImage bmImg = new BitmapImage();
    
    using (MemoryStream memStream2 = new MemoryStream()) 
    {
       img.Save(memStream2, System.Drawing.Imaging.ImageFormat.Png);
       ms.Position = 0;
    
       bmImg.BeginInit();
       bmImg.CacheOption = BitmapCacheOption.OnLoad;
       bmImg.UriSource = null;
       bmImg.StreamSource = memStream2;
       bmImg.EndInit();
    }
    

提交回复
热议问题