首页 > Web开发 > 详细

ASP.NET MVC 动态加载图像

时间:2014-05-06 10:02:19      阅读:508      评论:0      收藏:0      [点我收藏+]


        private ImageInfo CreateImageFile(string fileName)
        {
            if (!File.Exists(fileName))
                return null;
            Image image = Image.FromFile(fileName);
            MemoryStream ms = new MemoryStream();
            image.Save(ms, ImageFormat.Png);
            image.Dispose();
            ImageInfo result = new ImageInfo();
            result.contentType = "image/png";
            result.fileContents = ms.ToArray();
            return result;
        }

        public ActionResult DisplayImage(string fileName)
        {
            ImageInfo imageInfo = CreateImageFile(Server.MapPath(fileName));
            if (imageInfo == null)
                return imageInfo == null ? "" : File(imageInfo.fileContents, imageInfo.contentType);
        }

    <img src=‘/Home/DisplayImage?fileName=myimage.jpg‘>

 

ASP.NET MVC 动态加载图像,布布扣,bubuko.com

ASP.NET MVC 动态加载图像

原文:http://www.cnblogs.com/sungang3225/p/3710700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!