日期:2014-05-17  浏览次数:20525 次

web页面动态显示图片
本帖最后由 stone1314 于 2013-11-09 16:18:22 编辑
这个是前台界面的
   <a  onclick="ExaminePictureFun('@name.Key')" href="javascript:void(0)"  >图片链接为:</a> 
<img id="imgPic" title="imgPicCake" alt="蛋糕照片!" /> 



        ExaminePictureFun = function (val) {
            $("#imgPic").attr("src", "/Order/Picture?PictureID=" + val); 
        }


这个是collection

        public ActionResult Picture(string PictureID)
        { 
            return new ImageResult()
            {
                byteStream = (byte[])dic[PictureID]
            };
        }



        public class ImageResult : ActionResult
        { 
            public ImageResult() { }  
            public byte[] byteStream; 

            //重写ExecuteResult 
            public override void ExecuteResult(ControllerContext context)
            {
                // 设置响应设置

                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.HttpContext.Response.BufferOutput = false;
                FileStream filestream = null;
                // 将图像流写入响应流中 
                const int buffersize = 1024 * 32;
                byte[] buffer = new byte[buffersize];
                int count = filestream.Read(buffer, 0, buffersize);
                while (count > 0)
                {
          &nb