我想要一种在编辑后快速显示 SoftwareBitmap 的方法。
目前,Image 控件仅支持使用 BGRA8 编码且预乘或无 Alpha 通道的图像。在尝试显示图像之前,请进行测试以确保其格式正确,如果不正确,请使用 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;
Run Code Online (Sandbox Code Playgroud)
您还可以使用SoftwareBitmapSource将 SoftwareBitmap 设置为 ImageBrush 的 ImageSource。有关更多信息,请参阅创建、编辑和保存位图图像。