Windows Phone - MediaLibrary

本文关键字:MediaLibrary Phone Windows | 更新日期: 2023-09-27 17:58:14

这是我的代码。
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);

在模拟器上,所有内容都被保存。但在设备上显示错误"发生意外错误"。

Windows Phone - MediaLibrary

直接保存流不起作用?

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);