C# 如何在UWP C中将SVG转换为可写位图#
我们可以在UWP中从1703加载SVG。 谁能提供一个机制,,C# 如何在UWP C中将SVG转换为可写位图#,c#,svg,uwp,C#,Svg,Uwp,我们可以在UWP中从1703加载SVG。 谁能提供一个机制,, 如何将SVG转换为C#UWP中的WriteableBitmap。不幸的是,没有这样的api可以直接将SVG转换为WriteableBitmap图像,因为当我们将文件转换为WriteableBitmap时,我们需要使用如下所示的BitmapDecoder类,但不支持SVG类型 private static async Task<WriteableBitmap> OpenWriteableBitmapFile(Storage
如何将SVG转换为C#UWP中的WriteableBitmap。不幸的是,没有这样的api可以直接将SVG转换为
WriteableBitmap
图像,因为当我们将文件转换为WriteableBitmap
时,我们需要使用如下所示的BitmapDecoder
类,但不支持SVG类型
private static async Task<WriteableBitmap> OpenWriteableBitmapFile(StorageFile file)
{
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
WriteableBitmap image = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
image.SetSource(stream);
return image;
}
}
private async void RenderTargetBitmapToWriteableBitmap(UIElement element)
{
var bitmap = new RenderTargetBitmap();
await bitmap.RenderAsync(element);
var pixelBuffer = await bitmap.GetPixelsAsync();
byte[] pixels = pixelBuffer.ToArray();
var wb = new WriteableBitmap((int)bitmap.PixelWidth, (int)bitmap.PixelHeight);
using (Stream stream = wb.PixelBuffer.AsStream())
{
await stream.WriteAsync(pixels, 0, pixels.Length);
}
}