[WP7] Add images in the Windows Phone 7 Media Library

The Windows Phone 7 emulator included in the beta developer
tool doesn’t contain
any images in the Media Library. It’s not very easy to test an
application that
asks the user to choose an image to use the application.
a few lines of code which helps you to add images in the Media Library
emulator. Please note that images are not being saved when you close the
emulator !

When you
look the media library in the WP7, there is nothing:

You must
add in the project the assembly Microsoft.Xna.Framework.Media. It allows you to
access the Media Library and to save images with the SavePicture method :


an “Images” folder in the project, and add images (or photos) in this folder.
For each images, change the following properties as the following screenshot:

And use
the following lines of code to add the images in the Media Library:

MediaLibrary myMediaLibrary = new MediaLibrary();
Uri myUri = new Uri(@”Images/Jellyfish.jpg”,

System.IO.Stream photoStream =
byte[] buffer = new byte[photoStream.Length];

photoStream.Read(buffer, 0,

myMediaLibrary.SavePicture(“Jellyfish.jpg”, buffer);

When you have added several images, this is what you can see in the WP7 emulator:

4 thoughts on “[WP7] Add images in the Windows Phone 7 Media Library

Leave a Reply

Your email address will not be published. Required fields are marked *