WP7 Sample–Create a JPG screenshot of Bing maps control
Today I saw a colleague ask an interesting question, how do you create a screenshot of a map that can be used in a list as a thumbnail? so I did some digging and came up with this sample that can be downloaded from the link below.http://cid-c6b45be43711d8b8.skydrive.live.com/self.aspx/Code%20Samples/wp7Sample.ScreenshotOfMap.zipIn summary for those who don’t want to download the sample app, most of the work is done inside of the “Take picture” button, here is the source:// Store the size of the map control
int Width = (int)mapTest.RenderSize.Width;
int Height = (int)mapTest.RenderSize.Height;// Write the map control to a WriteableBitmap
WriteableBitmap screenshot = new WriteableBitmap(mapTest, new TranslateTransform());
using (MemoryStream ms = new MemoryStream())
{
// Save it to a memory stream
screenshot.SaveJpeg(ms, Width, Height, 0, 100);// Take saved memory stream and put it back into an BitmapImage
BitmapImage img = new BitmapImage();
img.SetSource(ms);// Assign to our image control
ImageFromMap.Width = img.PixelWidth;
ImageFromMap.Height = img.PixelHeight;
ImageFromMap.Source = img;// Cleanup
ms.Close();
}
WP7 Sample–Create a JPG screenshot of Bing maps control
Today I saw a colleague ask an interesting question, how do you create a screenshot of a map that can be used in a list as a thumbnail? so I did some digging and came up with this sample that can be downloaded from the link below.
http://cid-c6b45be43711d8b8.skydrive.live.com/self.aspx/Code%20Samples/wp7Sample.ScreenshotOfMap.zip
In summary for those who don’t want to download the sample app, most of the work is done inside of the “Take picture” button, here is the source:
// Store the size of the map control
int Width = (int)mapTest.RenderSize.Width;
int Height = (int)mapTest.RenderSize.Height;
int Width = (int)mapTest.RenderSize.Width;
int Height = (int)mapTest.RenderSize.Height;
// Write the map control to a WriteableBitmap
WriteableBitmap screenshot = new WriteableBitmap(mapTest, new TranslateTransform());
using (MemoryStream ms = new MemoryStream())
{
// Save it to a memory stream
screenshot.SaveJpeg(ms, Width, Height, 0, 100);
WriteableBitmap screenshot = new WriteableBitmap(mapTest, new TranslateTransform());
using (MemoryStream ms = new MemoryStream())
{
// Save it to a memory stream
screenshot.SaveJpeg(ms, Width, Height, 0, 100);
// Take saved memory stream and put it back into an BitmapImage
BitmapImage img = new BitmapImage();
img.SetSource(ms);
BitmapImage img = new BitmapImage();
img.SetSource(ms);
// Assign to our image control
ImageFromMap.Width = img.PixelWidth;
ImageFromMap.Height = img.PixelHeight;
ImageFromMap.Source = img;
ImageFromMap.Width = img.PixelWidth;
ImageFromMap.Height = img.PixelHeight;
ImageFromMap.Source = img;
// Cleanup
ms.Close();
}
ms.Close();
}
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment