如何下载和网页保存图像? [英] How can I download and save images from the web?

查看:184
本文介绍了如何下载和网页保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Windows Phone 7的应用程序,将节省一些图片从网上,我不知道在那里我可以,或者我可以从网络到手机上保存图像。

I'm trying to make a Windows Phone 7 app that will save some images off the web, I have no idea where I can or if I can save images from the web to the phone.

我能做些什么来保存图像?

What can I do to save images?

推荐答案

在手机上,你可以使用HttbWebRequest(建议避免每次我张贴在这里的项目UI影响)或Web客户端。

On the phone, you can use HttbWebRequest (recommended to avoid UI impact) or WebClient per the project I posted here.

WebClient的,HttpWebRequest和在Windows Phone 7 UI线程

您可以然后把你的流,并将其传递到这种​​形式的东西将它写入独立存储。

You can then take your stream and pass it into something of this form 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。请注意,这将使与用户的照片在图片中心混合的照片。

Jon is correct you can also use MediaLibrary.SavePicture. Be aware that this would put the pics mixed in with the users photos in the Picture Hub.

这是直线前进的。

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

在独立存储中存储它基本上是你的应用的私密文件系统。

Storing it in isolated storage is basically your apps private file system.

这篇关于如何下载和网页保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆