Windows Phone - MediaLibrary

时间:2013-02-07 12:49:05

标签: c# windows-phone

这是我的代码。

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

在模拟器上,一切都已保存。但在设备上显示错误“发生意外错误”。

1 个答案:

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