我正在使用 Visual Studio 2012、C#、Silverlight、Windows Phone 8 应用程序。
我们从网络服务获取数据,通过网络服务我们得到一张图片,它是一个 base64 字符串。
我把它转换成一个字节数组,现在我想把它保存到windows phone的存储中,使用内存流?我不知道这是否是正确的方法。我不想将它保存到独立存储,只是本地文件夹,因为我想在有人点击链接后显示图片。
这就是我目前所拥有的。
byte[] ImageArray;
var image = Attachmentlist.Attachment.ToString();
imagename = Attachmentlist.FileName.ToString();
ImageArray = Convert.FromBase64String(image.ToString());
StorageFolder myfolder = Windows.Storage.ApplicationData.Current.LocalFolder;
await myfolder.CreateFileAsync(imagename.ToString());
StorageFile myfile = await myfolder.GetFileAsync(imagename.ToString());
MemoryStream ms = new MemoryStream();
所以在我初始化内存流之后,我如何获取字节数组并将其写入存储文件,然后再次检索它?
最佳答案
要将文件写入光盘,请尝试以下代码:
StorageFile sampleFile = await myfolder.CreateFileAsync(imagename.ToString(),
CreateCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(sampleFile, ImageArray);
内存流创建写入内存的流,因此不适用于此问题。
关于c# - 将字节数组写入Windows Phone中的存储文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16891574/