Accessing Pictures from Media Library in Windows Phone

You may come across a requirement to access the entire picture saved in Media Library of Windows Phone. Media Library can be access using MediaLibrary class.

To work with MediaLibrary class you need to add reference of Microsoft.Xna.Framework. This class is defined in namespace Microsoft.Xna.Framework.Media namespace.

To work with MediaLibrary, you need to make instance of MediaLibrary class as below,


Pictures property of MediaLibrary class returns all the images as Picture. You can iterate to all images as below,


Image can be fetch as stream inside foreach look as below,


You can create Image from returend stream as below.


Eventually you can set imageToShow as source of Image control. For your reference below code will add all the pictures from Media Library in a listbox called lstImageFromMediaLibrary

MediaLibrary m = new MediaLibrary();

foreach (var r in m.Pictures)
Stream imageStream = r.GetImage();

var imageToShow = new Image()
Source = PictureDecoder.DecodeJpeg(r.GetImage())


You can access Media Library on emulator only in debugmode. In this way you can access all the images from Media library. I hope this post is useful. Thanks for reading.


Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

2 thoughts on “Accessing Pictures from Media Library in Windows Phone”

  1. Pingback:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s