How to download and save images from the Internet?

I am trying to make a Windows Phone 7 application that will save some images from the Internet, I don’t know where I can, or if I can save images from the Internet to my phone.

What can I do to save images?

+5
source share
2 answers

On the phone, you can use HttbWebRequest (it is recommended to avoid the influence of the user interface) or WebClient for the project that I posted here.

WebClient, HttpWebRequest and user interface on Windows Phone 7

Then you can take your stream and transfer it to something like that to write it to isolated storage.

private void PicToIsoStore(Stream pic) {
    using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
        var bi = new BitmapImage();
        bi.SetSource(pic);
        var wb = new WriteableBitmap(bi);
        using (var isoFileStream = isoStore.CreateFile("somepic.jpg")) {
            var width = wb.PixelWidth;
            var height = wb.PixelHeight;
            Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
        }
    }
}

, MediaLibrary.SavePicture. , Picture Hub.

,

private void PicToMediaLibary(Stream pic) {
     MediaLibrary lib = new MediaLibrary();
     lib.SavePicture("blah", pic);
}

- , , .

+5

WebClient WebRequest, .

- , , , , . ( Microsoft.Phone.Tasks, . , .)

EDIT: , . MediaLibrary SavePicture... XNA, Silverlight. , API XNA Silverlight, . .

+6

All Articles