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)
                {


                }

            }

        }

  • 相关阅读:
    TAM安装需求和过程
    【转】OpenCV灰色直方图
    【原】Windows编程中的字符集编码格式及_T宏的解释
    【转】拷贝构造函数/深拷贝/浅拷贝
    【转】OpenCV实现KNN算法
    【原】opencv中cvCopy()和cvCloneImage()的区别:
    【转】数据挖掘十大经典算法KNN
    【原】函数返回一个指针以及返回STL对象的问题
    【原】关于c中int a=1; int b=a类型问题的思考
    【转】AfxMessageBox、MessageBox、::MessageBox的区别
  • 原文地址:https://www.cnblogs.com/Cruise-Yang/p/9518537.html
Copyright © 2011-2022 走看看