public void ImgSave() { string url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F3d3bbb5626df7c0a52b0e665eea40a45dde19b051b795-9m8Sul_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1620482119&t=3e28067466a4e0a77c6e820d01061c77"; WebRequest imgRequest = WebRequest.Create(url); HttpWebResponse res; try { res = (HttpWebResponse)imgRequest.GetResponse(); } catch (WebException ex) { res = (HttpWebResponse)ex.Response; } if (res.StatusCode.ToString() == "OK") { System.Drawing.Image downImage = System.Drawing.Image.FromStream(res.GetResponseStream()); string deerory = string.Format(@"D:\img{0}", DateTime.Now.ToString("yyyy-MM-dd")); string fileName = string.Format("{0}.png", DateTime.Now.ToString("HHmmssffff")); if (!System.IO.Directory.Exists(deerory)) { System.IO.Directory.CreateDirectory(deerory); } downImage.Save(deerory + fileName); downImage.Dispose(); } }
原文:https://www.cnblogs.com/yueyongsheng/p/14635180.html