Skip to main content

WP7 Sample–Create a JPG screenshot of Bing maps control

WP7 Sample–Create a JPG screenshot of Bing maps control

image
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.
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;
// 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();
}

Comments

Popular posts from this blog

Creating Custom Events in C#

First of all, to read and understand this article you should be familiar with these concepts of C# language: Inheritance Events Delegates Just to remind them very quickly: Inheritance is a feature of OOP. You can create a class and then you can create another class which has the same properties and methods of the class it is inheriting from. This could be useful for example when you need to create a class for objects like cars. You create a basic Car class and then you create some classes that inherits from Car, and in their body you add methods and/or properties. The C# syntax for inheriting a class is this: class BaseClass { /*body of the BaseClass here */ } class DerivedClass : BaseClass { /*body of the DerivedClass here */ } Events and delegates are two concepts that very often work together. When something happens on a windows form (like a click, dblclick, changin some text, selecting an item in a combobox, moving mouse, pressing a key and so on) an event is raise...

How to use Application Bar in Windows Phone 7 Application ?

      If you are working with Windows Phone 7, the first thing that you should have noticed is the very own Application bar. Application Bar is present in most of the applications that you use in your Windows Phone 7. This is basically a standard Toolbar with a menu associated with it which allows you to enumerate the commonly used commands in a standard location. While creating your application, Microsoft strongly recommends you to add an application bar, to ensure the user have common behaviour for every application. You can think Application bar similar to TaskBar of windows. Components of Application Bar An application Bar is made up with two components: 1. ApplicationBar Buttons 2. ApplicationBar Menu The applicationbar buttons are always visible for an application which is used to list only the items that needed to be frequently used while dealing with the application. Lets say you create a Text processing application, you can list the File->Ope...