这是我的代码。
MediaLibrary myMediaLibrary = new MediaLibrary();
Uri myUri = new Uri(@"Images/Jellyfish.jpg", UriKind.Relative);
System.IO.Stream photoStream = App.GetResourceStream(myUri).Stream;
byte[] buffer = new byte[photoStream.Length];
photoStream.Read(buffer, 0, Convert.ToInt32(photoStream.Length));
myMediaLibrary.SavePicture("Jellyfish.jpg", buffer);
在模拟器上,一切都已保存。但在设备上显示错误“发生意外错误”。
答案 0 :(得分:0)
直接保存您的Stream不起作用?
MediaLibrary myMediaLibrary = new MediaLibrary();
Uri myUri = new Uri(@"Images/Jellyfish.jpg", UriKind.Relative);
System.IO.Stream photoStream = App.GetResourceStream(myUri).Stream;
myMediaLibrary.SavePicture("Jellyfish.jpg", photoStream);
或者,您可以使用WriteableBitmap
并将其保存到Stream
,然后使用MediaLibray
保存。
wr.SaveJpeg(FileStream, wr.PixelWidth, wr.PixelHeight, 0, 85);