C# 根据图片Http地址变为本地图片并放进压缩包

本文介绍了如何使用C#编写代码实现将特定目录下的图片压缩为.zip文件,并下载指定URL的图片到本地。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

不作详述

    public void getAll(string filePath)
        {


            string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();
            string strReturn = @"E:/work/";

            filePath = @"E:\work\test\" + filename+".zip";
            using (Zip zip = new Zip(filePath, Zip.CompressionLevel.Default))
            {
                zip.AppendDirectory("E:\\work\\test\\img");
                zip.AppendString(Downloader.DownloadPicture("\\img.jpg", "", 200), Zip.CombinEntry("img", filename + ".jpg"));
            }

            Response.Write(strReturn);
        }

 

 

      public static byte[] DownloadPicture(string picUrl, string savePath, int timeOut)
        {
            //bool value = false;
            WebResponse response = null;
            Stream inStream = null;
            Stream outStream = null;
             byte[] buffer = new byte[1024];
            string resultCode = "";
            try
            {

               
                WebClient mywebclient = new WebClient();
                string url = "_\\upload_img.jpg";
                string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".jpg";
                string filepath = @"F:\" + newfilename;
                try
                {
                    buffer = mywebclient.DownloadData(url);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.ToString());
                }
                return buffer;
            }
            finally
            {
                if (response != null) response.Close();
            }
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值