我有图片网址。
如何在WP 8.1中将保存到隔离存储。
是否可以同时触发 保存 ,然后只需一个按钮即可 分享 进入Facebook?
这是我的代码 - 在BurakKaanKöse之后很有效:
public async void GetImage()
{
StorageFolder folder = ApplicationData.Current.LocalFolder;
if (folder != null)
{
StorageFile file = await folder.CreateFileAsync("imagefile", CreationCollisionOption.ReplaceExisting);
string url = imgUri[fLFl.SelectedIndex].ToString();
HttpClient client = new HttpClient();
byte[] fileContent = await client.GetByteArrayAsync(url); ; // This is where you set your content as byteArray
Stream fileStream = await file.OpenStreamForWriteAsync();
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Flush();
fileStream.Dispose();
}
}
答案 0 :(得分:0)
不要忘记更改'imagefile'路径和fileContent变量。
private async void SaveFile()
{
try
{
StorageFolder folder = ApplicationData.Current.LocalFolder;
if(folder != null)
{
StorageFile file = await folder.CreateFileAsync("imagefile", CreationCollisionOption.ReplaceExisting);
byte[] fileContnet = null; // This is where you set your content as byteArray
Stream fileStream = await file.OpenStreamForWriteAsync();
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Flush();
fileStream.Close();
}
}
catch (Exception ex)
{
// Some Exception handling code
}
}