猿问

从System.Drawing.Bitmap加载WPF BitmapImage

从System.Drawing.Bitmap加载WPF BitmapImage

我有一个实例System.Drawing.Bitmap并希望将其以下形式提供给我的wpf应用程序:System.Windows.Media.Imaging.BitmapImage.

最好的方法是什么?


慕盖茨4494581
浏览 2027回答 3
3回答

梵蒂冈之花

从内存流加载它怎么样?using(MemoryStream memory = new MemoryStream()){     bitmap.Save(memory, ImageFormat.Png);     memory.Position = 0;     BitmapImage bitmapImage = new BitmapImage();     bitmapImage.BeginInit();     bitmapImage.StreamSource = memory;     bitmapImage.CacheOption = BitmapCacheOption.OnLoad;     bitmapImage.EndInit();}
随时随地看视频慕课网APP
我要回答