⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagehandler.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 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 );
			}
        }



	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -