Winwdos Phone 从手机中读取相册图片
首先声明一个存图片的类:
public class FlowItem { public string Name { get; set; } public ImageSource Picture { get; set; } public ImageBrush BackupgroupPicture { get; set; } }
声明一个图片集合:
private ObservableCollection<FlowItem> _pictureList = new ObservableCollection<FlowItem>();
得到所有的图片:
void GetWP7Picture() { MediaLibrary library = new MediaLibrary(); _pictureCollection = library.Pictures; if (_pictureCollection.Count == 0) return; foreach (Picture _p in _pictureCollection) { Stream _s = _p.GetImage(); BitmapImage _bi = new BitmapImage(); _bi.SetSource(_s); FlowItem _w = new FlowItem(); _w.Picture = _bi; _w.Name = _p.Name; ImageBrush ib = new ImageBrush(); ib.ImageSource = _bi; _w.BackupgroupPicture = ib; _pictureList.Add(_w); } }