Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在UWP C中将SVG转换为可写位图#_C#_Svg_Uwp - Fatal编程技术网

C# 如何在UWP C中将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

我们可以在UWP中从1703加载SVG。 谁能提供一个机制,,
如何将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);
    }
}