JKennedy
JKennedy

Reputation: 18799

Getting Local Photos Windows Phone 8 Emulator

So I have taken some Photos on my windows phone emulator and I am then trying to find them in my application. So Far I have:

PictureCollection CameraRollPictures;
using (var library = new MediaLibrary())
{
    //taking all albums
     PictureAlbumCollection allAlbums = library.RootPictureAlbum.Albums;
     //taking Camera Roll album separately from all album
     PictureAlbum cameraRoll = allAlbums.Where(album => album.Name == "Camera Roll").FirstOrDefault();
     // here you will get camera roll picture list
     CameraRollPictures = cameraRoll.Pictures;
}

But this keeps crashing because cameraRoll = null. Is this feature available on WP8 emulator or am I doing something wrong?

My method to get photos is from this stackoverflow question

EDIT I have also tried album.Name == "Camera Roll"

Windows Phone Photos

Upvotes: 2

Views: 526

Answers (2)

JKennedy
JKennedy

Reputation: 18799

So the answer was simple... My method worked perfectly but I needed to:

  • go into the WMAppManifest.Xml
  • go to Capabilities
  • tick ID_CAP_MEDIALIB_PHOTO

This provides read-only access to photos in the media library

Upvotes: 2

Sajeetharan
Sajeetharan

Reputation: 222582

MediaSource mediaSource = MediaSource.GetAvailableMediaSources()
            .First((source => source.MediaSourceType == MediaSourceType.LocalDevice));
using (MediaLibrary mediaLibrary = new MediaLibrary(mediaSource))
{
     PictureAlbum cameraRollAlbum = mediaLibrary.RootPictureAlbum.Albums.First((album) => album.Name == "Camera Roll");

}

or use PhotoChooserTask

You can upload Images to an Emulator as mentioned here

Upvotes: 1

Related Questions