:::: MENU ::::

Screen capture to media library instead of isolated storage

One of the things REALLY missing on Windows Phone is the ability to take screenshots inside of your application, because emulator often doesn’t let you do what you like. One of the things is that when you want to load and display data such as photos and music, it only gives you a few shots available, but there’s no way for you to use your own photos or your own music. In this article, I’ll edit one class for screen capturing which you can use in your application, and show you how to save it to the media library of the phone.

I found that one of the best classes, and the best code for taking screenshots on Windows Phone on Jeff Wilcox blog. He wrote a class called ScreenCapture.cs released under Apache 2 license

I felt it would be easier is to save the image to the media library of the phone. Instead, it originally saves the screenshot to IsolatedStorage of the application, and does it every X seconds, where X is the number you give to the method ScreenShots.BeginTakingPictures(). If you don’t give a parameter to the function, it takes 2 seconds as a default value.

To save to your media library, simply add the reference to Microsoft.Xna.Framework to your projects references and add the following line at the beginning of the class

and then instead of saving to isolated storage like this:

use MediaLibrary class:

Now, this method can fill your media libary and your phone with unnecessary images. I, on the other hand, like to be in control of that, so instead of using dispatcher timer, I will recommend a method which should be removed before publishing to Marketplace, but you can use it for your internal testing and screenshot taking.

Whenever you want to take a screenshot, just override OnDoubleTap event handler on your page. Just write:

If you are using double tap somewhere in your app and this is inconvenient, use something else to trigger the TakePicture method. The TakePicture method uses the code from the ScreenShots class, which now looks like this:

I hope this will help you take screenshots! I took one to demonstrate the results, and I used the app from my previous blog post.

screenshots 634563717655260000

Of course, I used the code above with Jeff’s permission on Twitter! :)

image

Enjoy! :)

Share the knowledge

No Comments

So, what do you think ?