I have a universal solution with platform supporting Windows Phone. After the user has tapped on Bing Maps, a pin is created an snapshot of the map is also created, but this image doesn't contain the pin.
I am using Windows.UI.Xaml.Controls.Maps.MapControl with this xaml:-
XAML:
<mp:MapControl x:Name="mpWinPh"
Grid.Row="1"
Width="{Binding ElementName=ControlRoot,
Path=Width}"
Height="{StaticResource ActivityLogGfxSize}"
MapServiceToken="{Binding Credentials}"
MapTapped="mpWinPh_MapTapped" />
C#:
private async void mpWinPh_MapTapped(MapControl sender, MapInputEventArgs args)
{
var location = args.Location;
BasicGeoposition snPosition = new BasicGeoposition
{
Latitude = location.Position.Latitude,
Longitude = location.Position.Longitude,
Altitude = location.Position.Altitude
};
Geopoint snPoint = new Geopoint(snPosition);
MapIcon icon = new MapIcon { Location = snPoint };
mpWinPh.Center = snPoint;
mpWinPh.ZoomLevel = 15;
mpWinPh.MapElements.Clear();
mpWinPh.MapElements.Add(icon);
Field.GpsCoordinate coordinate = new Field.GpsCoordinate { Latitude = location.Position.Latitude, Longitude = location.Position.Longitude };
(viewModel as LocationControlViewModel).UpdateGps(coordinate);
await SaveImage();
}
private async Task SaveImage()
{
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(mpWinPh);
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
var pixels = pixelBuffer.ToArray();
// Useful for rendering in the correct DPI
var displayInformation = DisplayInformation.GetForCurrentView();
var stream = new InMemoryRandomAccessStream();
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
displayInformation.RawDpiX,
displayInformation.RawDpiY,
pixels);
await encoder.FlushAsync();
stream.Seek(0);
byte[] resizedData = new byte[stream.Size];
await stream.ReadAsync(resizedData.AsBuffer(), (uint)stream.Size, InputStreamOptions.None);
await SaveStreamToTempLocation(() => Task.FromResult(new MemoryStream(resizedData) as Stream));
}