【发布时间】:2011-12-04 11:00:24
【问题描述】:
由于我缺乏编程经验(3 个月),我无法重新创建上述问题的任何已找到示例。我发现的示例与非 WP7 Silverlight(基于相机的图像保存)有关,对于我的需求来说已经很复杂,或者只是没有用。我已经能够使用 Webclient 的实例下载文本文件,并使用 StreamWriter 将其保存到隔离存储中。我需要用 jpg 图像完成相同的任务。以下是我用来下载文本文件的内容。
================================================ =================================
IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication();
private void GetTextFile()
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://mywebsite.com/textfile.txt"));
}
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
StreamWriter MyStreamWriter = new StreamWriter(new IsolatedStorageFileStream("textfile.txt", FileMode.Create, MyStore));
MyStreamWriter.WriteLine(e.result)
MyStreamWriter.Close();
}
================================================ =================================
我已经删除了一些用于处理错误等的行,以使其尽可能简单。
请有人修改以上内容以使我能够下载并保存 jpg?
请尽量简单,因为我很容易混淆。
提前感谢您的宝贵时间!
已解决!=============================================== ====================================
我设法使用下面此站点的信息使其正常工作。 http://dotnet.dzone.com/articles/operating-image-files-windows
希望这对未来其他沮丧的新手有所帮助!
IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication();
private void GetImageFile()
{
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri("http://mywebsite.com/1.jpg"), client);
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var resInfo = new StreamResourceInfo(e.Result, null);
var reader = new StreamReader(resInfo.Stream);
byte[] contents;
using (BinaryReader bReader = new BinaryReader(reader.BaseStream))
{
contents = bReader.ReadBytes((int)reader.BaseStream.Length);
}
IsolatedStorageFileStream stream = MyStore.CreateFile("10.jpg");
stream.Write(contents, 0, contents.Length);
stream.Close();
}
【问题讨论】:
标签: .net silverlight windows-phone-7 webclient isolatedstorage