欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

制作远程缩略图

程序员文章站 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;
            }
        }