是否可以将 SVG 添加到 MapIcon.Image 以便在 UWP 地图控件中显示?
Is it possible to add an SVG to a MapIcon.Image for display in a UWP Map Control?
我可以毫无问题地添加 PNG 图像来更改默认的 MapIcon 图像,但是一旦我尝试使用 SVG,应用程序就会崩溃并显示“application.exe 已退出,代码为 -529697949 (0xe06d7363) 'Microsoft C++ Exception'.
我知道 SvgImageSource class,我可以在应用程序的其他区域使用它来渲染 SVG 图像,但是当我尝试将 SVG 添加到 MapIcon.Image 时;这是 IRandomAccessStreamReference 类型,它不起作用。我只是想知道这是否是 API 的限制,以及在 MapIcon 上显示自定义图像时我是否应该只使用位图而不是 SVG?
我在下面添加了一个快速失败示例。
MainPage.xaml:
<Page xmlns:my="using:Windows.UI.Xaml.Controls.Maps"
x:Class="TestMapWithSVGForMapIcon.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<my:MapControl Loaded="{x:Bind _viewModel.AddMapIcon}"/>
</Grid>
</Page>
MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
private MainViewModel _viewModel;
public MainPage()
{
InitializeComponent();
_viewModel = new MainViewModel();
DataContext = _viewModel;
}
}
MainViewModel.cs:
public class MainViewModel
{
protected MapControl Map { get; set; }
public void AddMapIcon(object sender, RoutedEventArgs e)
{
if (sender is MapControl map)
{
Map = map;
}
var mapIcon = new MapIcon
{
Location = new Geopoint(new BasicGeoposition()
{
Latitude = 53.795452,
Longitude = -4.304733
}),
//works Ok with .png files
Image = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/Hazard_H1.svg")),
};
Map.MapElements.Add(mapIcon);
}
}
不,SVG 不是 MapIcon.Image 支持的流类型
您可以使用包含 PNG 或 JPG 格式的编码光栅图像或 RGB 格式的原始字节数组的流。
我可以毫无问题地添加 PNG 图像来更改默认的 MapIcon 图像,但是一旦我尝试使用 SVG,应用程序就会崩溃并显示“application.exe 已退出,代码为 -529697949 (0xe06d7363) 'Microsoft C++ Exception'.
我知道 SvgImageSource class,我可以在应用程序的其他区域使用它来渲染 SVG 图像,但是当我尝试将 SVG 添加到 MapIcon.Image 时;这是 IRandomAccessStreamReference 类型,它不起作用。我只是想知道这是否是 API 的限制,以及在 MapIcon 上显示自定义图像时我是否应该只使用位图而不是 SVG?
我在下面添加了一个快速失败示例。
MainPage.xaml:
<Page xmlns:my="using:Windows.UI.Xaml.Controls.Maps"
x:Class="TestMapWithSVGForMapIcon.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<my:MapControl Loaded="{x:Bind _viewModel.AddMapIcon}"/>
</Grid>
</Page>
MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
private MainViewModel _viewModel;
public MainPage()
{
InitializeComponent();
_viewModel = new MainViewModel();
DataContext = _viewModel;
}
}
MainViewModel.cs:
public class MainViewModel
{
protected MapControl Map { get; set; }
public void AddMapIcon(object sender, RoutedEventArgs e)
{
if (sender is MapControl map)
{
Map = map;
}
var mapIcon = new MapIcon
{
Location = new Geopoint(new BasicGeoposition()
{
Latitude = 53.795452,
Longitude = -4.304733
}),
//works Ok with .png files
Image = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/Hazard_H1.svg")),
};
Map.MapElements.Add(mapIcon);
}
}
不,SVG 不是 MapIcon.Image 支持的流类型 您可以使用包含 PNG 或 JPG 格式的编码光栅图像或 RGB 格式的原始字节数组的流。