gpt4 book ai didi

c# - 在 WPF 中显示 Drawing.Image

转载 作者:IT王子 更新时间:2023-10-29 04:29:02 24 4
gpt4 key购买 nike

我有一个 System.Drawing.Image 的实例。

如何在我的 WPF 应用程序中显示它?

我尝试使用 img.Source 但这不起作用。

最佳答案

我有同样的问题,结合几个答案解决了。

System.Drawing.Bitmap bmp;
Image image;
...
using (var ms = new MemoryStream())
{
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;

var bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = ms;
bi.EndInit();
}

image.Source = bi;
//bmp.Dispose(); //if bmp is not used further. Thanks @Peter

来自 this question and answers

关于c# - 在 WPF 中显示 Drawing.Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10077498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com