c# - 在不保存到 UWP C# 文件的情况下在图像控件上显示 SoftwareBitmap

标签 c# image bitmap uwp uwp-xaml

有没有办法在不将 SoftwareBitmap 保存到文件的情况下在 Xaml Image 控件上显示 SoftwareBitmap?我想要一种在编辑后快速显示 SoftwareBitmap 的方法。

最佳答案

I want to have a quick way to display the SoftwareBitmap after edit.

目前,Image 控件仅支持使用 BGRA8 编码和预乘或无 alpha channel 的图像。在尝试显示图像之前,测试以确保它具有正确的格式,如果不正确,请使用 SoftwareBitmap 静态 Convert 方法将图像转换为支持的格式。

if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
    softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}

var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(softwareBitmap);

// Set the source of the Image control
imageControl.Source = source;

您还可以使用 SoftwareBitmapSource 将 SoftwareBitmap 设置为 ImageBrush 的 ImageSource。更多请引用Create, edit, and save bitmap images .

关于c# - 在不保存到 UWP C# 文件的情况下在图像控件上显示 SoftwareBitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48156631/

相关文章:

java - 如何将包含位图的对象传递给另一个 Activity

android - 设置为 ImageView 后回收位图

预期的 c# 标识符?

C# using 语句更多理解

c# - 如何使用 async 和 await 发出大量并发 Web 请求?

ruby-on-rails - 图片未在生产中显示

android - BitmapFactory.decodeStream 内存不足,尽管使用了减少的样本大小

c# - 如何在 C# 中实现分段文本框,强制用户以特定格式输入值?

java - 如何在jsp中将字节数据显示到img标签中?

vb.net - 如何在VB.NET中的图像上创建鼠标悬停工具提示?