?? imagehandler.cs
字號:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing;
using System.Data.SqlTypes;
//*********************************************************************
//
// ImageHandler Class
//
// This HTTP Handler intercepts all requests for images and
// handles the requests by generating the image from the database.
//
//*********************************************************************
public class ImageHandler : IHttpHandler {
//*********************************************************************
//
// IsReusable Property
//
// Required by the HttpHandler interface. Indicates whether
// the same class can be reused for future requests.
//
//*********************************************************************
public bool IsReusable {
get {return true;}
}
//*********************************************************************
//
// ProcessRequest Method
//
// Determines the type of image being requested and displays it.
//
//*********************************************************************
public void ProcessRequest(HttpContext context)
{
int width = -1;
int height = -1;
bool thumbnail = false;
// If we don't have section info, then leave
SectionInfo objSectionInfo = (SectionInfo)context.Items["SectionInfo"];
if (objSectionInfo == null)
return;
// Get image parameters from query string
if (context.Request.QueryString["width"] != null)
width = Int32.Parse(context.Request.QueryString["width"]);
if (context.Request.QueryString["height"] != null)
height = Int32.Parse(context.Request.QueryString["height"]);
if (context.Request.QueryString["thumbnail"] != null)
thumbnail = true;
// Check if image is a community image (its a number)
string fileName = Path.GetFileNameWithoutExtension(context.Request.Path);
if (CommunityGlobals.IsNumeric(fileName))
{
DisplaySectionImage(context, objSectionInfo.ID, Int32.Parse(fileName), width, height, thumbnail);
return;
}
// Assume named image
fileName = Path.GetFileName(context.Request.Path);
DisplayCommunityImage(context, fileName);
}
//*********************************************************************
//
// DisplaySectionImage Method
//
// Displays a section relative image. This is an image associated
// with a particular section such as a Photo Gallery section.
//
//*********************************************************************
private void DisplaySectionImage(HttpContext context, int sectionID, int imageID, int width, int height, bool thumbnail) {
context.Response.BinaryWrite( ImageUtility.GetSectionImage(sectionID, imageID, width, height, thumbnail));
}
//*********************************************************************
//
// DisplayCommunityImage Method
//
// Displays a global image. This type of image is available
// throughout the community.
//
//*********************************************************************
private void DisplayCommunityImage(HttpContext context, string fileName) {
SqlDataReader dr;
dr = ImageUtility.GetCommunityImage(fileName);
if(dr.Read()) {
SqlBinary buffer= (byte[])dr["Image_imageData"];
context.Response.ContentType = dr["Image_contenttype"].ToString();
context.Response.BinaryWrite((byte[])buffer );
}
dr.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -