简体   繁体   English

获取本地照片Windows Phone 8模拟器

[英]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. 因此,我在Windows Phone模拟器上拍摄了一些照片,然后尝试在应用程序中找到它们。 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 . 但这总是崩溃,因为cameraRoll = null Is this feature available on WP8 emulator or am I doing something wrong? WP8仿真器上是否提供此功能,或者我做错了什么?

My method to get photos is from this stackoverflow question 我获取照片的方法来自于这个stackoverflow问题

EDIT I have also tried album.Name == "Camera Roll" 编辑我也尝试过album.Name == "Camera Roll"

Windows Phone照片

So the answer was simple... My method worked perfectly but I needed to: 因此答案很简单...我的方法运行良好,但我需要:

  • go into the WMAppManifest.Xml 进入WMAppManifest.Xml
  • go to Capabilities 转到功能
  • tick ID_CAP_MEDIALIB_PHOTO 勾选ID_CAP_MEDIALIB_PHOTO

This provides read-only access to photos in the media library 这提供了对媒体库中照片的只读访问

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 或使用PhotoChooserTask

You can upload Images to an Emulator as mentioned here 您可以按照此处所述将图像上传到Emulator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM