1

Web から画像をダウンロードしようとしています。メディア ライブラリに保存します。以下は私のコードです。ここに何か不足していますか。よろしくお願いします。

  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);
        }

    }
4

3 に答える 3

3

以下のようにイベントハンドラーを追加します

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

次に、bitmapImage_DownloadProgress,作成WritableBitMapして保存します

于 2013-03-06T08:14:15.120 に答える
3
private void LoadIMG()
    {

        var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };


        bitmapImage.ImageOpened += bitmapImage_ImageOpened;
        bitmapImage.ImageFailed += bitmapImage_ImageFailed;
        bitmapImage.DownloadProgress += bitmapImage_DownloadProgress;
        bitmapImage.UriSource = new Uri("http://ds.serving-sys.com/BurstingRes///Site-16990/Type-0/7b912e70-352a-454f-8ea7-5d5ecd6ebfae.gif");
    }

    private void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
    {

    }

    private void bitmapImage_ImageFailed(object sender, ExceptionRoutedEventArgs e)
    {

    }

    private void bitmapImage_ImageOpened(object sender, RoutedEventArgs e)
    {
         var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication(); 
         var writeableBitmap = new WriteableBitmap(sender as BitmapImage);
         var isolatedStorageFileStream = userStoreForApplication.CreateFile("Myfile.gif");
         writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85); 
    }
于 2013-03-06T08:09:41.007 に答える
0

あなたはそれを試すことができます:http ://www.kunal-chowdhury.com/2012/02/how-to-download-and-save-images-in-wp7.html#.TzUtWBSaLkM.twitter

お役に立てれば。

于 2013-03-06T07:57:03.203 に答える