Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Accessing Pictures from a Picture Album

This section demonstrates how to access pictures in a picture album by using the Media API on Windows Phone.

Complete Sample

The code in the topic shows you the technique for using Media API to access pictures. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Accessing Pictures

This example retrieves and displays pictures from a device's media library.

Dd254867.note(en-us,XNAGameStudio.41).gifNote
Picture collections will always be empty on Xbox 360 and Windows; therefore, the following example work only on Windows Phone.

To retrieve pictures

  1. Declare variables.

    ICollection<MediaSource> mediaSources;
    MediaLibrary mediaLib;
    PictureCollection picCollection;        
    Texture2D pic;
    
  2. Call MediaSource.GetAvailableMediaSources to retrieve the available media on the device.

    // Retrieve all available media libraries on the device
    mediaSources = MediaSource.GetAvailableMediaSources();
    
  3. Call MediaLibrary to get the media libraries from the device.

    mediaLib = new MediaLibrary();
    
  4. Obtain the picture collection from the media library.

    picCollection = mediaLib.Pictures;
    
  5. Get a picture's texture from the collection.

    pic = Texture2D.FromStream(GraphicsDevice, picCollection[currentPic].GetImage());
    
  6. Display the picture on-screen.

    protected override void Draw(GameTime gameTime)
    {           
        GraphicsDevice.Clear(Color.CornflowerBlue);
        Vector2 pos = Vector2.Zero;
        spriteBatch.Begin();
        spriteBatch.Draw(pic, pos, Color.White);
        spriteBatch.End();
    
        base.Draw(gameTime);
    }
    

Concepts

Playing a Video
Demonstrates how to use the VideoPlayer to play a video.
Playing a Song from a URI
Demonstrates how to use the MediaPlayer to play a song from a Uniform Resource Identifier (URI).
Displaying Pictures and Playing Video
Provides overviews about how to use the Media API to retrieve system media, including pictures, songs, and video.

Reference

MediaLibrary Class
Provides access to songs, playlists, and pictures in the device's media library.
PictureCollection Class
A collection of pictures in the media library.

Community Additions

Show:
© 2014 Microsoft