ThinkGeo.com    |     Documentation    |     Premium Support

Create an image (png, jpg,...) from silverlight control

Hi,



Is there a way to export Map content in Silverlight to any bitmap format (jpg, png, …)?

I am using Map class from ThinkGeo.MapSuite.SilverlightEdition namespace.









Hi Rustam, 
  
 I found somebody mentioned WriteableBitmap class maybe helpful for your requirement. 
  
 stackoverflow.com/questions/4499559/silverlight-draw-on-bitmap 
  
 Or you should want to loop all overlay and layers, then create your graphic and draw on it one by one, but not all overlay can support draw by this way. 
  
 Regards, 
  
 Don

Hi Don,



Thanks for your answer!



I tried with WriteableBitmap. It draws on it correctly, but when I’m trying to access Pixels property of the bitmap, it throws an exception:



System.Security.SecurityException

"WriteableBitmap has protected content. Pixel access is not allowed."

   at System.Windows.Media.Imaging.WriteableBitmap.get_Pixels()



I need to get pixels and send it to a web service.



Also I tried to draw layers, it’s OK with all my features layers, but found no way to draw World Image.

I am using  WriteableBitmapGeoCanvas from ThinkGeo.MapSuite.SilverlightCore.

Do you know how can I draw a world image on it?



Thanks,

Rustam


Hi Rustam, 
  
 About draw layers, what’s the world image? If you meant something like GoogleMaps or BingMaps, I think we cannot draw them follow this way. If your world image is rendered by local shape file, you can just handle it as a common layer. 
  
 I am sorry for WriteableBitmap I don’t have further experience on it, if you want to solve related issue I think maybe you want to search more related topic. 
  
 Regards, 
  
 Don

Sorry for the delay.



The world map is the picture, that I am drawing using BingMapsOverlay class.



Thanks!

Hi Rustam,



I guess there are 2 options, just outline them as following:



1.  Use BingMapsLayer from MapSuiteCore instead, thus we can export it image(png, Jpg etc.).

2. Please try the solution mentioned at 

stackoverflow.com/questions/1139200/using-fjcore-to-encode-silverlight-writeablebitmap, where shows how to export a WritableBitmap into a Base64String.



Thanks,

Johnny