/// /// 製作遠程縮略圖 /// /// 圖片URL /// 新圖路徑 /// 最大寬度 /// 最大高度 public static void MakeRemoteThumbnailImage(string url, string newFileName, int maxW... ...
/// <summary> /// 製作遠程縮略圖 /// </summary> /// <param name="url">圖片URL</param> /// <param name="newFileName">新圖路徑</param> /// <param name="maxWidth">最大寬度</param> /// <param name="maxHeight">最大高度</param> public static void MakeRemoteThumbnailImage(string url, string newFileName, int maxWidth, int maxHeight) { Stream stream = GetRemoteImage(url); if(stream == null) return; Image original = Image.FromStream(stream); stream.Close(); MakeThumbnailImage(original, newFileName, maxWidth, maxHeight); } /// <summary> /// 獲取圖片流 /// </summary> /// <param name="url">圖片URL</param> /// <returns></returns> private static Stream GetRemoteImage(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.ContentLength = 0; request.Timeout = 20000; HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); return response.GetResponseStream(); } catch { return null; } }