• C#照片预览,好处是图片不在项目中也可以查看


    //在一个页面中添加image控件,后台指向一个新页面,在新页面获取图片的二进制流,再展现在页面上
    <body>
        <div class="pNavigation">
            <div style="overflow: hidden;">
                <img alt="" class="img_Navigation" src="/Style/Images/Default/pixel.gif" />当前位置:消防设备管理
                >> 消防设备图纸查看
            </div>
        </div>
        <form id="form1" runat="server">
        <table id="table" cellpadding="0" cellspacing="0" border="0" style=" 100%;
            margin: 0px;">
            <tr>
                <td align="center">
                    <img id="imgphoto" src="~/Style/Images/Photo/nopic.gif" runat="server" style="margin: 2px;
                        margin-left: 12px; height: 280px;  222px;" />
                </td>
            </tr>
        </table>
        </form>
    </body>
    protected void Page_Load(object sender, EventArgs e)
            {
                try
                {
                    Model.LOGISTICS_BUILDINGEQUIPMENTPIC model = cBll.GetList(" where t.LYH='" + Request.QueryString["lyh"] + "' and t.LC='" + Request.QueryString["lc"] + "'""").FirstOrDefault();
                    if (model != null)
                    {
                        this.imgphoto.Src = "ShowPhoto.aspx?lyh=" + Request.QueryString["lyh"] + "&lc=" + Request.QueryString["lc"] + "&r=" + new Random().Next().ToString(CultureInfo.InvariantCulture);
                        
                    }
                }
                catch (Exception exception)
                {
                    Log.fWriterLog("住校管理之床位安排查看页(学生信息查看)页面初始化异常:" + exception.Message, exception);
                }
            }

    //新页面输出图片二进制流
    /// <summary>
            
    /// 获取图片
            
    /// </summary>
            
    /// <param name="lyh"></param>
            
    /// <param name="lc"></param>
            protected void GetShowPhoto(string lyh,string lc)
            {
                Model.LOGISTICS_BUILDINGEQUIPMENTPIC model = cBll.GetList(" where t.LYH='" + lyh + "' and t.LC='" + lc + "'""").FirstOrDefault();
                string basePath = Hzjg.Common.Config.ConfigManage.fGetAppConfig("SaveFilePath");
                basePath = basePath.Substring(0, basePath.Length - 1);
                byte[] byteImg = null;//图片流
                Stream stream = null;
                if (model != null)
                {
                    //把文件转化为二进制流
                    string path = basePath + model.PICTUREPATH.Replace("/""\");
                    byteImg = ConvertToBinary(path);
                    stream = new MemoryStream(byteImg);
                }
                else
                {
                    FileStream f = new FileStream(Server.MapPath("~/Style/Images/Photo/nopic.jpg"), FileMode.Open, FileAccess.Read);
                    byteImg = new byte[f.Length];
                    f.Read(byteImg, 0, byteImg.Length);
                    f.Close();
                    stream = new MemoryStream(byteImg);
                }
                var img = (Bitmap)Image.FromStream(stream, false); //转换成Bitmap 
                Response.Buffer = false;
                Response.ContentType = "image/jpg";
                Response.AddHeader("Content-Disposition""attachment;filename=photo.jpg"); //照片名称叫photo.jpg 
                Response.BinaryWrite(byteImg); //写入二进制流 
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }

            /// <summary>
            
    /// 把文件转化为二进制流
            
    /// </summary>
            
    /// <param name="Path">文件路径</param>
            
    /// <returns></returns>
            public static byte[] ConvertToBinary(string Path)
            {
                FileStream stream = new FileInfo(Path).OpenRead();
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
                return buffer;
            }
  • 相关阅读:
    cocos2d-x lua 学习笔记(1) -- 环境搭建
    Cocos2d-x 3.x 如何编译成安卓程序
    Cocos2d-x 3.4 初体验——安装教程
    cocos2d-x 之 CCProgressTimer
    android sdk离线安装
    在cocos2d-x-3.0 android 平台编译时提示CocosGUI.h: No such file or directory
    cocos2d_x iconv转码
    cocos2d-x发生undefined reference to `XX'异常 一劳永逸解决办法
    libjpeg.a exists or that its path is correct
    UE4插件
  • 原文地址:https://www.cnblogs.com/zecVip/p/4506667.html
Copyright © 2020-2023  润新知