Hello there,
Here a simple code I tried to make to take screenshots inside a Windows Phone 7 application. This works in the emulator. I'm pretty sure it will work with a phone.
I found this article to take screenshots with few lines of code: Screen Capture on Windows Phone 7.
The issue here is that you only have a Bitmap image in the phone's memory. What I did is:
- a simple web application for IIS able to receive a screenshot (you may host it on your local IIS)
- a class for your WP7 application to send screenshots to the web server
You will find an attached file named Wp7Screenshots.rar. It contains a Visual Studio 2010 solution to build & publish on your local IIS (or anywhere you like).
If you look at the code, you will find a simple IHttpHandler. It's main goal is to detect files in a HTTP POST query and to save them on your hard drive.
After publishing, make sure the web application contains a Files folder and verify IIS have permission to create files into it.
Now, let's see you WP7 application. This only apply to Silverlight projects. So if you are using XNA, perhaps this blog entry is not for you.
The only configuration you have to do is to set the URL of your deployed HttpHandler. You can do this anywhere.
Tools.ScreenshotSender.UploadUrl = "http://172.24.1.32/wp7/Upload.ashx?key=fvkjorejv";
Then, you have to call the magic method to take the screenshot. You need a reference to a PhoneApplicationPage. Here is a code to take a screenshot 5 seconds after the application startup. You can of course use any event to take more screenshots (mouse click, navigation event, timer...).
public partial class MainPage : PhoneApplicationPage {
public MainPage() {
InitializeComponent();
Tools.ScreenshotSender.UploadUrl = "http://172.24.1.32/wp7/Upload.ashx?key=fvkjorejv";
// go off-thread to wait
ThreadPool.QueueUserWorkItem(r => {
Thread.Sleep(5000);
var dispatcher = r as Dispatcher;
// go on the UI thread to take a screenshot
dispatcher.BeginInvoke(new Action(() => {
Tools.ScreenshotSender.TakeAndSend(this);
}));
}, Deployment.Current.Dispatcher);
}
}
Don't forget this code was made from scratch. It is NOT ready for production. I wrote this to take screenshots for documentation purpose. If you want to use this in a published application, you might want to read the whole code file (for the silverlight application). And the server code IS INSECURE: anyone can upload any file to your webserver. The only simple protection is a hard-coded key. So again, sample insecure code here. You are free to enhance (and optionally post your own code).
Here is my C:\inetpub\wwwroot\wp7\Files folder with screenshots from the emulator.

Hope this can help. I'm still searching how to take a screenshot of a whole panorama control...