I want to be able to render an image from a RadMap control without displaying the map control. I can see the map control rendered in my png but the map background (in this case OSM) does not get rendered with the image. I assume this happens because the map data hasn't yet been retrieved.
public
class
MapRender
{
private
Thread _thread;
public
void
StartRender()
{
ThreadStart start = ScreenshotMap;
// Render;
_thread =
new
Thread(start);
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();
}
private
void
ScreenshotMap()
{
var imageSize = 800;
var osmBasedMapProvider =
new
OsmBasedMapProvider();
var radMap =
new
RadMap()
{
Provider = osmBasedMapProvider,
RenderSize =
new
Size(imageSize, imageSize), Height = imageSize, Width = imageSize
};
radMap.Loaded += RadMap_Loaded;
radMap.InitializeCompleted += RadMap_InitializeCompleted;
radMap.SizeChanged += RadMap_SizeChanged;
var c =
new
Canvas { Width = imageSize, Height = imageSize };
c.Children.Add(
new
Rectangle { Height = imageSize, Width = imageSize, Fill =
new
SolidColorBrush(Colors.Red) });
c.Children.Add(radMap);
var dpi = 80;
var bitmap =
new
RenderTargetBitmap((
int
)c.Width, (
int
)c.Height, dpi, dpi, PixelFormats.Default);
c.Measure(
new
Size((
int
)c.Width, (
int
)c.Height));
c.Arrange(
new
Rect(
new
Size((
int
)c.ActualWidth, (
int
)c.ActualHeight)));
bitmap.Render(c);
var png =
new
PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bitmap));
using
(Stream stm = File.Create(
"c:\\temp\\map.png"
))
{
png.Save(stm);
}
//radMap.ExportToImage("c:\\temp\\map2.png", true);
}
}
Is there some way for me to wait for the map data to be retrieved before saving the image file?
Thanks
Pete