asp.net生成缩略图示例方法分享(3)


//outpuimg.ashx?src=https://www.jb51.net/images/weimeidesc/8af30049-797e-4eb4-8a54-cc4de47c1694.jpg!100x100.jpg
        public void ProcessRequest(HttpContext context)
        {
            //获取图片
            string imgUrl = context.Request.QueryString["src"];
            string trueFilePath = imgUrl.Split('!')[0];
            //获取图片大小
            int width = Convert.ToInt32(imgUrl.Split('!')[1].Replace(".jpg", "").Split('x')[0]);
            int height = Convert.ToInt32(imgUrl.Split('!')[1].Replace(".jpg", "").Split('x')[1]);

            //图片已经存在直接输出
            if (File.Exists(context.Server.MapPath("~/" + imgUrl)))
            {
                OutPutImg("~/"+imgUrl);
            }
            else
            {
                if (!string.IsNullOrEmpty(imgUrl) && File.Exists(context.Server.MapPath("~/" + trueFilePath)))
                {
                    Image originalImage = System.Drawing.Image.FromFile(context.Server.MapPath("~/" + trueFilePath));
                    var newBitmap = new Bitmap(originalImage);
                    //生成相应的小图并保存
                    SendSmallImage(context.Server.MapPath("~/" + trueFilePath),context.Server.MapPath("~/" + imgUrl), width, height, "meiyouyisi");
                    //输出
                    OutPutImg("~/" + imgUrl);
                }
                else//图片如果不存在 输出默认图片
                {
                    //OutPutImg(imgUrl);
                }
            }
        }

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzppj.html