针对个人需求,在Xamarin.Forms.Map控件中,我需要创建一个CustomPin
扩展。 UWP部分(PCL项目)
我像这样创建了一个MapIcon
:
nativeMap.MapElements.Add(new MapIcon()
{
Title = pin.Name,
Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Pin/customicon.png")),
Location = new Geopoint(new BasicGeoposition() { Latitude = pin.Position.Latitude, Longitude = pin.Position.Longitude }),
NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0)
});
然而,通过这种方式,我无法设置Image
的尺寸。
我想从我的PCL部分使用一个Image
,将其调整大小并转换为IRandomAccessStreamReference
。为了实现这一点,我需要将Image
转换为流,但我找不到使其工作的方法 ><
所需函数示例:
private IRandomAccessStreamReference ImageToIRandomAccessStreamReference(Image image)
{
//Here I can set the size of my Image
//I convert it into a stream
IRandomAccessStreamReference irasr = RandomAccessStreamReference.CreateFromStream(/* img? */);
//irasr is then created from img
//I return the IRandomAccessStreamReference needed by the MapIcon element
return irasr;
}
注意: 参数Image
的img是一个Xamarin.Forms.Image
首先,这是否可能?如果是,则感谢任何可以帮助我的帮助..我已经搜索如何调整MapIcon的大小,但不能直接从类[MapIcon]中实现。(https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.maps.mapicon.aspx)
感谢您的帮助!