windows phone开发——本地相册
如何使用medialiberary将网络图片保存至手机相册。
首先获得网络图片的uri 然后将图片保存至独立存储空间,然后添加到我么的手机相册
更新清单文件,以便获得相应的权限
<Capability Name="ID_CAP_MEDIALIB_PHOTO"/>
后台代码
string name = "pic.jpg";
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (storage.FileExists(name))
storage.DeleteFile(name);
IsolatedStorageFileStream stream = storage.CreateFile(name);
Uri uri = new Uri("1.jpg", UriKind.RelativeOrAbsolute);
BitmapImage bmp = new BitmapImage(uri);
img.Source = bmp;
WriteableBitmap wbmp = new WriteableBitmap(bmp);
Extensions.SaveJpeg(wbmp, stream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 85);
stream.Close();
stream = storage.OpenFile(name, FileMode.Open, FileAccess.Read);
MediaLibrary library = new MediaLibrary();
Picture pic = library.SavePicture(name, stream);
stream.Close();