gpt4 book ai didi

c# - 从网络下载图像并存储在媒体库中 (windows phone 8)

转载 作者:太空宇宙 更新时间:2023-11-03 19:17:20 24 4
gpt4 key购买 nike

我正在尝试从网络上下载图像并将其保存在媒体库中,下面是我的代码,我在这里是否遗漏了什么,提前致谢

  public void storePicture()
{
try
{


using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{

string url = @"http://mynokiablog.com/wp-content/uploads/2012/11/wp8.jpeg";

BitmapImage storeimage = new BitmapImage(new Uri(url));

// height and width are 0
int testheight = storeimage.PixelHeight;
int testwidth = storeimage.PixelWidth;
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("testname");
// NullRefrenceException
WriteableBitmap wb = new WriteableBitmap(storeimage);

wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}

}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

}

最佳答案

如下添加事件处理器

    storeimage.ImageOpened += bitmapImage_ImageOpened;
storeimage.ImageFailed += bitmapImage_ImageFailed;
storeimage.DownloadProgress += bitmapImage_DownloadProgress;

然后在bitmapImage_DownloadProgress中创建WritableBitMap并保存

关于c# - 从网络下载图像并存储在媒体库中 (windows phone 8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15241325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com