制作远程缩略图
程序员文章站
2024-01-13 22:21:52
/// /// 制作远程缩略图 /// /// 图片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; } }
上一篇: 使用PS时,新手和老手的区别