.net 从存储和本地读取图片,并可放大图片
关键功能代码
1 /// <summary> 2 /// 获取病例图片 3 /// </summary> 4 /// <param name="class_sign"></param> 5 /// <returns></returns> 6 public string BindContentData(string class_sign) 7 { 8 StringBuilder sbWishing; 9 StringBuilder sbAllWishing = new StringBuilder(); 10 if (this.tb_patientID.Text.Trim().ToString().Length > 0 && this.tb_visitID.Text.Trim().ToString().Length > 0) 11 { 12 DataSet ds = DBSQLHelpers.Query("select * from v_mr_doc_index where patient_id='" + this.tb_patientID.Text.Trim() + "' and visit_id='" + this.tb_visitID.Text.Trim() + "' and class_sign in (" + class_sign + ") order by class_sign,cast(substring(Doc_No,charindex('_',Doc_No)+1,len(Doc_No)-charindex('_',Doc_No)) as int) asc"); 13 if (ds == null || ds.Tables.Count <= 0 || ds.Tables["ds"].Rows.Count <= 0) 14 { 15 //以下注意顺序问题,设置在return 之前 16 return "无相关内容,请选择相应病历列表项目查询!"; 17 } 18 else 19 { 20 foreach (DataRow row in ds.Tables["ds"].Rows) 21 { 22 //<img src="images/1.jpg" layer-pname="HTML5资源教程 - 1"> 23 24 sbWishing = new StringBuilder(); 25 DateTime dt_NetStoreValue = DateTime.ParseExact(ConfigurationManager.AppSettings["ImageUrlKey"], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); //20190515 26 DateTime dt_DataValue = DateTime.ParseExact(@row["DOC_PATH"].ToString().Substring(1, 8), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);//20191205 27 28 if (dt_DataValue <= dt_NetStoreValue)//若病例日期<存储上的最后日期,从存储上取 29 { 30 picPath = row["DOC_PATH"].ToString(); 31 sbWishing.Append("<a style=\"display:block;float:left;width:300px;height:300px;\" href=\"../ShowOutSiteImage.ashx?file=" + picPath + "\" class=\"highslide\" " + 32 " onclick=\"return hs.expand(this, { captionId: 'caption1' } )\"><span><img src=\"../ShowOutSiteSmallImage.ashx?file=" + picPath + "\" style=\"width:300px;height:300px;\" ></span>-</a>"); 33 34 } 35 else//从本地取 36 { 37 picPath = ConfigurationManager.AppSettings["Store"] + row["DOC_PATH"].ToString().Replace("\\", "/"); 38 sbWishing.Append("<a style=\"display:block;float:left;width:300px;height:300px;\" href=\"../" + picPath + "\" class=\"highslide\" " + 39 " onclick=\"return hs.expand(this, { captionId: 'caption1' } )\"><span><img src=\"../" + picPath + "\" style=\"width:300px;height:300px;\" ></span>-</a>"); 40 } 41 //追加到输出字符串中 42 sbAllWishing.Append(sbWishing.ToString()); 43 // sbAllWishing.Append(picPath); 44 } 45 } 46 } 47 else 48 { 49 return "无相关内容"; 50 } 51 return sbAllWishing.ToString(); 52 }
WebConfig文件
<appSettings>
<add key="StorePath" value="D:\Mr_Pic\"/>
<add key="Store" value="MrDocs"/>
<add key="ImageUrlKey" value="20190515"/>
<add key="ImageUrlValue" value="ShowOutSiteImage.ashx?file=\\192.168.10.12\\Multimedia\\EmrDocBackup"/>
</appSettings>
ShowOutSiteImage.ashx 点击看大图
<%@ WebHandler Language="C#" Class="ShowOutSiteImage" %> using System; using System.Web; using System.IO; using System.Configuration; public class ShowOutSiteImage : IHttpHandler { public void ProcessRequest(HttpContext context) { string path = context.Request.QueryString["file"]; if (File.Exists(path)) { System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); br.Close(); fs.Close(); context.Response.OutputStream.Write(bytes, 0, bytes.Length); return; } string storePath = HttpContext.Current.Request.PhysicalApplicationPath; storePath = storePath.Substring(0,storePath.Length-1); //context.Response.Write(storePath+"<br/>"); string remoteDir = ConfigurationManager.AppSettings["FTP.RemoteDir"]; string[] dirs=remoteDir.Split('\\'); FtpClient ftpClient = new FtpClient( ConfigurationManager.AppSettings["FTP.HostName"] , dirs[0] , ConfigurationManager.AppSettings["FTP.UserName"] , ConfigurationManager.AppSettings["FTP.Password"] , 21); for(int i=1;i<dirs.Length;i++) { if(dirs[i].Length>0) { ftpClient.ChDir(dirs[i]); } } string[] paths = path.Split('\\'); for(int i=0;i<paths.Length-1;i++) { if(paths[i].Length>0) { //context.Response.Write(paths[i]+"<br/>"); ftpClient.ChDir(paths[i]); } } string fileName=Guid.NewGuid().ToString("N"); //context.Response.Write(path+"<br/>"); ftpClient.Get(paths[paths.Length-1],storePath,fileName); ftpClient.DisConnect(); string file = storePath + "\\" + fileName; //context.Response.Write(file); if(File.Exists(file)) { byte[] buffer = File.ReadAllBytes(file); context.Response.OutputStream.Write(buffer, 0, buffer.Length); File.Delete(file); } } public bool IsReusable { get { return false; } } }
ShowOutSiteSmallImage.ashx 小图展示
<%@ WebHandler Language="C#" Class="ShowOutSiteSmallImage" %> using System; using System.Web; using System.IO; using System.Configuration; using System.Drawing; public class ShowOutSiteSmallImage : IHttpHandler { public void ProcessRequest(HttpContext context) { string path = context.Request.QueryString["file"]; // if (File.Exists(path)) { System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); br.Close(); fs.Close(); context.Response.OutputStream.Write(bytes, 0, bytes.Length); return; } string storePath = HttpContext.Current.Request.PhysicalApplicationPath; storePath = storePath.Substring(0,storePath.Length-1); //context.Response.Write(storePath+"<br/>"); string remoteDir = ConfigurationManager.AppSettings["FTP.RemoteDir"]; string[] dirs=remoteDir.Split('\\'); FtpClient ftpClient = new FtpClient( ConfigurationManager.AppSettings["FTP.HostName"] , dirs[0] , ConfigurationManager.AppSettings["FTP.UserName"] , ConfigurationManager.AppSettings["FTP.Password"] , 21); for(int i=1;i<dirs.Length;i++) { if(dirs[i].Length>0) { ftpClient.ChDir(dirs[i]); } } string[] paths = path.Split('\\'); for(int i=0;i<paths.Length-1;i++) { if(paths[i].Length>0) { //context.Response.Write(paths[i]+"<br/>"); ftpClient.ChDir(paths[i]); } } string fileName=Guid.NewGuid().ToString("N"); //context.Response.Write(path+"<br/>"); ftpClient.Get(paths[paths.Length-1],storePath,fileName); ftpClient.DisConnect(); string file = storePath + "\\" + fileName; //context.Response.Write(file); if(File.Exists(file)) { byte[] buffer = File.ReadAllBytes(file); buffer = ImageHelper.ImageToBit(ImageHelper.BitToImage(buffer),10); context.Response.OutputStream.Write(buffer, 0, buffer.Length); File.Delete(file); } } public bool IsReusable { get { return false; } } }
JS文件
<script src="Myjs/highslide/highslide.js" type="text/javascript"></script> <script type="text/javascript"> // remove the registerOverlay call to disable the controlbar hs.registerOverlay( { thumbnailId: null, overlayId: 'controlbar', position: 'top right', hideOnMouseOut: true } ); hs.graphicsDir = 'Myjs/highslide/graphics/'; hs.outlineType = 'rounded-white'; hs.captionEval = 'this.thumb.title'; </script>
展示效果图:


浙公网安备 33010602011771号