挑战:
如何有效地将 System.Drawing.Bitmap 图像合并到使用 System.Windows.Media.Imaging.BitmapImage 的 WPF 应用程序中?
解决方案:
简化的方法利用 MemoryStream 进行转换:
using System.IO; using System.Windows.Media.Imaging; using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); memoryStream.Position = 0; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memoryStream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); }
此技术将位图保存到 MemoryStream,从而可以在 WPF 环境中直接访问和使用。 然后生成的 bitmapImage
即可在 WPF 控件中使用。
以上是如何在wpf中显示system.drawing.bitmap?的详细内容。更多信息请关注PHP中文网其他相关文章!