zoukankan      html  css  js  c++  java
  • 从网络路径下载图片

    using System;
    using System.Drawing;
    using System.IO;
    using System.Net;

    /// <summary>
        /// 图片操作
        /// </summary>
        public class ImageDownload
        {

            /// <summary>
            /// 从网络下载图片并保存到指定路径
            /// </summary>
            /// <param name="param_WebImageUrl">图片网络Url</param>
            /// <param name="param_Localpath">本地路径</param>
            /// <param name="param_SavaImageFileNmae">图片名称</param>
            public void DownloadImageAndSavaToLoca(string param_WebImageUrl, string param_Localpath, string param_SavaImageFileNmae)
            {
                WebRequest ImageResqust = WebRequest.Create(param_WebImageUrl);
                HttpWebResponse res;
                try
                {
                    res = (HttpWebResponse)ImageResqust.GetResponse();
                }
                catch (WebException ex)
                {

                    res = (HttpWebResponse)ex.Response;
                }
                try
                {
                    //图片下载成功
                    if (res.StatusCode.ToString() == "OK")
                    {//以流的方式保存图片
                        Image downimage = Image.FromStream(ImageResqust.GetResponse().GetResponseStream());
                        //------保存图片到本地------
                        if (!Directory.Exists(param_Localpath))
                        {
                            Directory.CreateDirectory(param_Localpath);
                        }
                        downimage.Save(param_Localpath + param_SavaImageFileNmae);
                        downimage.Dispose();
                    }
                }
                catch (Exception ex)
                {


                }

            }

        }

  • 相关阅读:
    解决ajax 发送post 请求时csrf_token 问题
    pip 常用命令
    mac 查看端口的使用情况
    使用from __future__ import unicode_literals
    git 使用
    django rest_framework
    Apache JMeter 接口压力测试
    HTTP 协议
    自定义异步非阻塞web框架
    WebSocket
  • 原文地址:https://www.cnblogs.com/Cruise-Yang/p/9518537.html
Copyright © 2011-2022 走看看