因为项目上需要加载在线卫星云图,因此写了这个功能来把卫星云图下载的本地,在这里记录一下:

string imageUrl=“http://image.nmc.cn/product/2018/08/06/WXCL/SEVP_NSMC_WXCL_ASC_E99_ACHN_LNO_PY_20180806051500000.JPG?v=1533532726321”;
string _ImagePath = AppDomain.CurrentDomain.BaseDirectory + "Resources\\CloudImages\\"+“test.JPG”;

上面为图片地址和本地文件夹的设置。

接下来是图片下载相关代码:

                        HttpWebRequest request = HttpWebRequest.Create(imageUrl) as HttpWebRequest;
HttpWebResponse response = null;
response = request.GetResponse() as HttpWebResponse;if (response.StatusCode != HttpStatusCode.OK) continue;
Stream reader = response.GetResponseStream();
FileStream writer = new FileStream(_ImagePath, FileMode.OpenOrCreate, FileAccess.Write);
byte[] buff = new byte[];
int c = ; //实际读取的字节数
while ((c = reader.Read(buff, , buff.Length)) > )
{
writer.Write(buff, , c);
}
writer.Close();
writer.Dispose();
reader.Close();
reader.Dispose();
response.Close();

C#之通过图片地址下载图片的更多相关文章

  1. Java学习笔记——IO操作之以图片地址下载图片

    以图片地址下载图片 读取给定图片文件的内容,用FileInputStream public static byte[] mReaderPicture(String filePath) { byte[] ...

  2. C++根据图片url下载图片

    需要使用到URLDownloadToFile()函数,该函数在头文件<urlmon.h>中声明. URLDownloadToFile()函数的定义如下: HRESULT URLDownlo ...

  3. URL地址下载图片到本地

    package test.dao; import eh.base.dao.DoctorDAO; import eh.entity.base.Doctor; import junit.framework ...

  4. java根据图片的url地址下载图片到本地

    package com.daojia.haobo.aicircle.util; import sun.misc.BASE64Encoder; import java.io.*; import java ...

  5. IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)

    编写一个如下界面,实现: 1.在文本输入框中输入一个网址,然后点击显示图片,图片显示到UIImageView中. 2.点击下载,这张显示的图片被下载到手机的Documents文件夹下的Dowmload ...

  6. vue2.0生成二维码图片并且下载图片到本地兼容写法

    vue生成二维码图片,这里使用的是qrcode.js 这个插件(亲测写法,兼容没有问题) 第一步,下载插件 需要注意,这里下载的是qrcodejs2 cnpm install --save qrcod ...

  7. php把采集内容中图片地址下载并替换成本地地址

    把字符串中地址全部获取到一个数组我们利用preg_match_all函数 代码如下 复制代码 <?php$str='<p><img border="0" s ...

  8. java通过图片URL下载图片

    public InputStream getInputStream(String imgUrl) { InputStream inputStream = null; try{ HttpURLConne ...

  9. Java已知图片路径下载图片到本地

    public static void main(String[] args) { FileOutputStream fos = null; BufferedInputStream bis = null ...

随机推荐

  1. 将Hive统计分析结果导入到MySQL数据库表中(一)——Sqoop导入方式

    https://blog.csdn.net/niityzu/article/details/45190787 交通流的数据分析,需求是对于海量的城市交通数据,需要使用MapReduce清洗后导入到HB ...

  2. BTM事务配置

    请参考原贴:http://thinkdifferent.iteye.com/blog/1450433 Tomcat6上配置BTM 博客分类: practice tomcatjava )去http:// ...

  3. 「小程序JAVA实战」小程序视频上传方法的抽象复用(57)

    转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxushipinshangchuanfangfadechouxiangfu ...

  4. Mysql 索引概论

    Mysql性能下降原因 JOIN连接过多 ,索引失效(单值,复合), 查询SQL过水, explian 语法分析SQL性能 https://blog.csdn.net/b1303110335/arti ...

  5. Python 2.75升级3.6.3

    https://blog.csdn.net/wwwdaan5com/article/details/78218277 Centos 7 默认yum安装python 是2.7.5, (网上看了很多升级都 ...

  6. list.contains

    list.contains(o),系统会对list中的每个元素e调用o.equals(e),方法,加入list中有n个元素,那么会调用n次o.equals(e),只要有一次o.equals(e)返回了 ...

  7. NotePad++替换行前、行后空格,替换空行

    用 Notepad++ 打开,把每一个将要放在表中单元格的内容放一行(注: ^ 代表行首 $ 代表行尾) 去除行尾空格和空白行:按CTRL+H 选择正则表达式– 查找目标:\s+$ 替换为空 去除行首 ...

  8. python模块的打包

    python模块的打包方法: http://blog.csdn.net/five3/article/details/7847551

  9. 19.Remove Nth Node From End of List(List; Two-Pointers)

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  10. xcode编译提示Permission denied

    编译第三方XCode插件时,提示没有文件操作权限(Permission denied) 使用命令行,修改Xcode目录当前用户操作权限: sudo chmod -R 777 /Users/当前的用户名 ...