Click here to Skip to main content
15,886,864 members
Articles / Web Development / ASP.NET

"Filmstrip" or CatalogView Photo Gallery Sample

Rate me:
Please Sign up or sign in to vote.
4.88/5 (53 votes)
4 Nov 2005CPOL10 min read 334.7K   7K   229  
A photo images gallery browsing template - CatalogView style.
  • catalogview_src.zip
    • CatalogView
      • bin
        • CatalogView.dll
      • CatalogView.csproj
      • CatalogView.csproj.webinfo
      • gallery.js
      • images
        • allrecords.gif
        • arrow.bmp
        • arrowdown.bmp
        • arrowleft.bmp
        • arrowup.bmp
        • btn_small_back_hover.gif
        • btn_small_next_hover.gif
        • btn_small_pause_hover.gif
        • BtnDkPink.gif
        • BtnPink.gif
        • BttnCllps.gif
        • BttnExpnd.gif
        • bullet.png
        • BULLET6x6.gif
        • button_back.gif
        • button_full.gif
        • button_fw.gif
        • button_pause.gif
        • button_stop.gif
        • buttonBlue_bg.gif
        • buttonsLaunch_02-sel.gif
        • Communication Centre.jpg
        • Communication Centre_thumb.jpg
        • control_back_up.gif
        • control_forward_up.gif
        • dotted-line.gif
        • download.png
        • folder_transparent.gif
        • ic012.gif
        • nav-next.gif
        • nav-next-disabled.gif
        • nav-prev.gif
        • nav-prev-disabled.gif
        • persphotos.png
        • play_streaming.gif
        • space.gif
      • photo
        • Cars
          • c439827a.jpg
          • c443596a.jpg
          • c448562a.jpg
          • c448636a.jpg
          • c450849a.jpg
          • c451115a.jpg
          • c451564a.jpg
          • c451593a.jpg
          • c451768a.jpg
          • c451777a.jpg
          • c453071a.jpg
          • c453251a.jpg
          • c455229a.jpg
          • c455439a.jpg
          • t448564a.jpg
          • vitg-plg2.jpg
          • xl7-lg3.jpg
        • Catalog1
          • 1.jpg
          • 2.jpg
          • 3.jpg
          • 3_ser_coup_download_08.jpg
          • 74.jpg
          • 74_thumb.jpg
        • CD
          • B000002NC2.01._SCLZZZZZZZ_.jpg
          • B00000JBFW.01._SCLZZZZZZZ_.jpg
          • B00000JBFX.01._SCLZZZZZZZ_.jpg
          • B00006879E.01._SCLZZZZZZZ_.jpg
          • B0000DZ3E2.01._SCLZZZZZZZ_.jpg
          • B0002F7I9Y.01._SCLZZZZZZZ_.jpg
          • B0006399FS.01._SCLZZZZZZZ_.jpg
          • B00064K2RQ.01._SCLZZZZZZZ_.jpg
          • B0006L16N8.01._SCLZZZZZZZ_.jpg
          • B0009HL7JM.01._SCLZZZZZZZ_.jpg
          • B000AA4JHU.01._SCLZZZZZZZ_.jpg
          • B000B5IPLK.01._SCLZZZZZZZ.jpg
        • Desktop
          • DesertSunrise.jpg
          • ForestDusk.jpg
          • LakeDusk.jpg
          • LakeSunset.jpg
          • MountainSunset.jpg
        • dvd
        • Flowers
          • crowpoison.jpg
          • paintbrush.jpg
          • winecup.jpg
          • winecup_thumb.jpg
      • PhotoGallery.aspx
      • PhotoGallery.aspx.cs
      • PhotoGallery.aspx.resx
      • PhotoView.ascx
      • PhotoView.ascx.cs
      • PhotoView.ascx.resx
      • styles.css
      • ThumbGen.cs
      • Web.config
using System;
using System.Web;
using System.Web.Util;
using System.Drawing;
using System.Drawing.Imaging;

namespace CatalogView
{
	/// <summary>
	/// Summary description for ThumbGen.
	/// </summary>
	public class ThumbGen : IHttpHandler
	{
		public void ProcessRequest (HttpContext context)
		{
			if (context.Request["path"]!=null)
				//we have a pth try process image
			{
				
				string img=(string)context.Request["path"];
				//here is path for application dir
				string path1=context.Server.MapPath(context.Request.ApplicationPath);
				path1=context.Server.MapPath(img);
				//img=path1+"\\"+img; //full path to image
				img=path1;
				System.Drawing.Image.GetThumbnailImageAbort myCallback =
				new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
				//get bitmap from file
				Bitmap bitmap = new Bitmap(img);
				// process image, create thumbnail. Try use to reduce size, instead of GetThubmnail
				ImageFormat imgformat=bitmap.RawFormat;
				//we will use fixed size for picture, in our case 69x90
				//but easy to add parameters such as width and calculate height
				
				/////////////////this code borrowed from Rick Strahl, http://west-wind.com/weblog
				//works better than NET method GetThumbnail() when need transparent gif
				//Bitmap bmpOut=new Bitmap(70,90);
				//Graphics g=Graphics.FromImage(bmpOut);
				//g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
				//g.FillRectangle(Brushes.White,0,0,69,90);
				//g.DrawImage(bitmap,0,0,69,90);
				///////////////////////////////////////////////////
				// ALternatively you can use 
				System.Drawing.Image imgOut=bitmap.GetThumbnailImage(58,76, myCallback, IntPtr.Zero);
				bitmap.Dispose();
				//but seems creating Black background for transparent GIF's
				//////////////////return our image back to stream
				context.Response.ContentType="image/jpeg";
				imgOut.Save(context.Response.OutputStream, ImageFormat.Jpeg);
				//bmpOut.Save(context.Response.OutputStream, ImageFormat.Jpeg);
				//bmpOut.Dispose();
				imgOut.Dispose();
			}
			
			//added Oct21, 2005. Try return 
			if (context.Request["Dir"]!=null)
			{
			//can we return array to client? Lets try.
				string curGallery=(string) context.Request["Dir"];
				string photodir=System.Configuration.ConfigurationSettings.AppSettings["photofolder"]; //or get from config file
				string[] photos=System.IO.Directory.GetFiles(context.Server.MapPath(photodir+"/"+curGallery),"*.jpg"); 
				int i=System.IO.Directory.GetParent(context.Server.MapPath(photodir)).FullName.Length;
				//
				//get files names/ relative path
				//just get actual files names for thumbnails and photos
				//just removing extra path, leaving only catalog and file name and the same time
				//convert string array to XMl document for returning back to client
				string photoxml="<gallery>";
				for (int ix=0; ix<photos.Length; ix++)
				{
					photos[ix]=photos[ix].Substring(i+1);
					photos[ix]=photos[ix].Replace("\\","/");
					photoxml=photoxml+"<photos>"+photos[ix]+"</photos>";
				}
				photoxml=photoxml+"</gallery>";
				context.Response.Clear();
				context.Response.ContentType="text/xml";
				//need fromat data to return back to client
				context.Response.Write(photoxml);
				context.Response.End();

			}


			
		}




		public bool IsReusable
		{
			get {return true;}
		}
		public bool ThumbnailCallback()
		{
			return false;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
Canada Canada
Trying to make software programming to second profession.
Doing programming for specific purpose, interesting by open data exchnage for building control systems.

Comments and Discussions