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 ="预览失败,文件不存在"});//"添加失败!"
                }
    
    
            }
    

      

  • 相关阅读:
    小程序如何实现rem
    Centos7通过yum跟源码编译安装Nginx
    VMware下的Centos7实践Kvm虚拟化(通俗易懂)
    XAI/MLI 可解释机器学习系列1- 开源&paper汇总
    CTR学习笔记&代码实现1-深度学习的前奏LR->FFM
    tensorflow feature_column踩坑合集
    第四篇-用Flutter手撸一个抖音国内版,看看有多炫
    第三篇-用Flutter手撸一个抖音国内版,看看有多炫
    第二篇-用Flutter手撸一个抖音国内版,看看有多炫
    使用Flutter开发的抖音国际版
  • 原文地址:https://www.cnblogs.com/lhlong/p/9871065.html
Copyright © 2011-2022 走看看