如何在WP8上将IBuffer保存到IStorageFile?

时间:2013-09-15 22:39:08

标签: windows-phone-8

Windows.Storage.FileIO.WriteBufferAsync方法,但WP8不支持。将缓冲区保存到手机上的存储文件的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您可以选择如何继续这里。但是,更轻松地使用IBuffer个对象所需的扩展名都位于System.Runtime.InteropServices.WindowsRuntime命名空间中。您可能还需要System.IO扩展名的private async void SaveBuffer(Windows.Storage.Streams.IBuffer myBuffer) { Windows.Storage.StorageFile myFile = await Windows.Storage.StorageFile.GetFileFromPathAsync("..."); using (var writeStream = await myFile.OpenStreamForWriteAsync()) { // Option 1: Cast to stream and copy myBuffer.AsStream().CopyTo(writeStream); // Option 2: Cast to byte array and write var content = myBuffer.ToArray(); writeStream.Write(content, 0, content.Length); } } 命名空间。

{{1}}

<强>价: