c# - 在图像控件中显示位图值

标签 c# wpf

我有一个位图,我想在图像控件中显示它而不保存它,我该怎么做?

最佳答案

将位图转换为 BitmapImage 并将其分配给图像控件的 Source 属性(即示例中的 CurrentImage)到:

MemoryStream ms = new MemoryStream();
_bitmap.Save(ms, ImageFormat.Png);
ms.Position = 0;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
CurrentImage = bi;

关于c# - 在图像控件中显示位图值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5446313/

相关文章:

wpf - 我可以在 DataTemplate 中使用 DataTemplateSelector 吗?

c# - WPF 切换 UIElements 在 DataTemplate 中的可见性

c# - Entity Framework 中扩展部分类的放置

c# - 解析半格式化文件

sql - 超时已过。操作完成前超时时间已过或服务器未响应

c# - 如何使用 MVVM 模式实现进度条

javascript - knockout - 通知属性(property)变更

c# - Osherove 的负面单元测试命名约定?

c# - 使用 "external"GetHashCode 和等于字典

c# - 合并在 PDF 中多次使用的同一图像