• 从网络路径下载图片


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


                }

            }

        }

  • 相关阅读:
    Git 简单使用
    java web 简单的分页显示
    java web 实现验证码
    第一个MapReduce程序
    xgboost安装指南(win10,win7 64位)
    受限玻尔兹曼机(Restricted Boltzmann Machine)分析
    卷积神经网络概述及python实现
    集体智慧编程_第二章(提供推荐)_1
    EditText的inputType常用取值
    关于泛型的一些细节
  • 原文地址:https://www.cnblogs.com/Cruise-Yang/p/9518537.html
Copyright © 2020-2023  润新知