zoukankan      html  css  js  c++  java
  • ASP.NET MVC 动态加载图像


            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'>

  • 相关阅读:
    python 元组及操作
    python 字典所有操作
    python 列表操作
    python 运算符
    python while循环
    python 分支语句 等值判断 逻辑运算符
    GDI+_从Bitmap里得到的Color数组值分解
    服务器设计策略
    服务器设计策略
    IOCP的缓冲区
  • 原文地址:https://www.cnblogs.com/sungang3225/p/3710700.html
Copyright © 2011-2022 走看看