DataList與Lightbox結合秀圖.(下)

摘要:DataList與Lightbox結合秀圖.(下)

此篇主要是針對imgHandler.ashx的部分

imgHandler.ashx 設定顯示的圖檔依等比例縮放

001 <%@ WebHandler Language="C#" Class="imgHandler" %>
002
003 <%@ WebHandler Language="C#" Class="imgHandler" %>
004
005 using System;
006 using System.Data;
007 using System.Configuration;
008 using System.Collections;
009 using System.Web;
010 using System.Web.Security;
011 using System.Web.UI;
012 using System.Web.UI.WebControls;
013 using System.Web.UI.WebControls.WebParts;
014 using System.Web.UI.HtmlControls;
015 using System.IO;
016 using System.Data.SqlClient;
017 using System.Drawing;

018
019 public class imgHandler : IHttpHandler
020 {
021
022     public void ProcessRequest(HttpContext context)
023     {
024         //指定圖片輸出格式
025         context.Response.ContentType = "image/jpeg";
026
027         讀取資料庫
052
053         //宣告一個 Byte 做資料處理用途
054         byte[] bytes = null;
055
056         try
057         {
058             if (ds.Tables[0].Rows.Count > 0)
059             {
060
061                 bytes = (byte[])ds.Tables[0].Rows[0][1];
062
063                 設定顯示的圖檔依等比例縮放
091             }

092
093         }

094         catch (Exception ex)
095         {
096             throw ex;
097         }

098
099     }

100
101     public bool IsReusable
102     {
103         get
104         {
105             return false;
106         }

107     }

108
109 }

110
111

 

imgHandlerO.ashx 設定顯示的圖檔原始大小

01 <%@ WebHandler Language="C#" Class="imgHandler" %>
02
03 <%@ WebHandler Language="C#" Class="imgHandler" %>
04
05 using System;
06 using System.Data;
07 using System.Configuration;
08 using System.Collections;
09 using System.Web;
10 using System.Web.Security;
11 using System.Web.UI;
12 using System.Web.UI.WebControls;
13 using System.Web.UI.WebControls.WebParts;
14 using System.Web.UI.HtmlControls;
15 using System.IO;
16 using System.Data.SqlClient;
17 using System.Drawing;

18
19 public class imgHandler : IHttpHandler
20 {
21
22     public void ProcessRequest(HttpContext context)
23     {
24         //指定圖片輸出格式
25         context.Response.ContentType = "image/jpeg";
26
27         讀取資料庫
52
53         //宣告一個 Byte 做資料處理用途
54         byte[] bytes = null;
55
56         try
57         {
58             if (ds.Tables[0].Rows.Count > 0)
59             {
60
61                 bytes = (byte[])ds.Tables[0].Rows[0][1];
62
63                 設定顯示的圖檔原始大小
78             }

79
80
81         }

82         catch (Exception ex)
83         {
84             throw ex;
85         }

86
87     }

88
89     public bool IsReusable
90     {
91         get
92         {
93             return false;
94         }

95     }

96
97 }

98
99

 不知為啥第1、3行會重覆出現 @@"