zoukankan      html  css  js  c++  java
  • web预览图片

     

      

    图片预览弹出框

        <!--弹出框--> 
        <!--
            作者:152645239@qq.com
            时间:2016-07-06
            描述:图片预览弹出框
        -->
        <div id="PicViewdlg" class="easyui-dialog" title="@BaseRes.SPS_TIT_005" style="600px;height:500px;padding:5px;" data-options=" 
    				toolbar: '#dlg-toolbar',
    				buttons: '#dlg-buttons',
    				closed:true
    			">
            <div style=" 650px; height: 450px; "> 
                <img id="picViewss" /> 
            </div> 
            <a class="easyui-linkbutton width80" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#PicViewdlg').dialog('close');">关闭</a>
        </div>
    

      

    图片预览js方法,需要传入路径

     //预览服务器图片
        //FilePath 文件路径,服务器可以访问的路径
        function picView(FilePath) {
            $.ajax({  
                type: 'POST',
                url: "/PackagingInformation/PicNowView?" + "fileUpd=" + encodeURIComponent(FilePath),
                //data: pars,
                cache: false,
                async: false,
                dataType: "json", 
                success: function (packJson) {  
                    if (packJson.result == 1) {
                         
                        var img = document.getElementById("picViewss");
                        //图片路径设置为读取的图片
                        img.src = packJson.Content.Content;  
                        $('#PicViewdlg').dialog({
                            title: '预览',
                             600,
                            height: 500,
                            closed: false,
                            cache: false,
                            modal: true
                        });
                        $('#PicViewdlg').window('center');
                        $('#PicViewdlg').dialog('open');
                    }
                    else {
    
                        $.messager.alert('@BaseRes.COM_CTL_NOTICE', packJson.Msg);
                    }
                }
            }); 
        };
    

      

    Controller方法

            /// <summary>
            /// 查看图片,返回图片数据
            /// </summary>
            /// <param name="fileUpd"></param>
            /// <returns></returns> 
            public JsonResult PicNowView(string fileUpd)
            {
                byte[] infbytes = new byte[0];
                try
                { 
                    FileStream fs = new FileStream(fileUpd, FileMode.Open, FileAccess.Read);
                    infbytes = new byte[(int)fs.Length];
                    fs.Read(infbytes, 0, infbytes.Length);
                    fs.Close();
    
                    var _Content= Content("data:image/png;base64," + Convert.ToBase64String(infbytes) + "", "text/html");
    
                    return Json(new { result = 1,Content=_Content, Msg = "获取成功" });//"添加失败!"
                }
    
                catch (Exception)
                {
    
                    return Json(new { result = 0, Msg ="预览失败,文件不存在"});//"添加失败!"
                }
    
    
            }
    

      

  • 相关阅读:
    怎样用一个3升的杯子和一个5升的杯子装出4升水来(杯子没有刻度)?
    HttpModule和Http Handler (比较与区别)
    Entity Framework 6新特性:全局性地自定义Code First约定
    ASP.NET MVC下的四种验证编程方式
    Json.Net
    JSON 序列化和反序列化——JavaScriptSerializer实现
    XML 命名空间(XML Namespaces)
    使用SQL Server存储ASP.NET Session变量
    ISV 和SI 是什么
    HTML,XML中的转义字符
  • 原文地址:https://www.cnblogs.com/lhlong/p/9871065.html
Copyright © 2011-2022 走看看