You may come across a requirement to access the entire picture saved in a Media Library of a Windows Phone. The Media Library can be accessed using the MediaLibrary class.
To work with the MediaLibrary class you need to add a reference for Microsoft.Xna.Framework. This class is defined in the namespace Microsoft.Xna.Framework.Media namespace.
To work with the MediaLibrary, you need to make an instance of the MediaLibrary class as below:
The Pictures property of the MediaLibrary class returns all the images as a Picture. You can iterate to all images as below:
An Image can be fetched as a stream inside a foreach; look below:
You can create an Image from a returned stream as below.
Eventually you can set imageToShow as source of Image control. For your reference the following 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 the Media Library in the emulator only in debugmode. In this way you can access all the images from Media library. I hope this article is useful. Thanks for reading.