<%@ Page language="c#" Inherits="ThumbnailsInDirectory" CodeFile="Default.aspx.cs" %>
ThumbnailsInDirectory
File: Default.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class ThumbnailsInDirectory : System.Web.UI.Page
{
protected void cmdShow_Click(object sender, System.EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(txtDir.Text);
gridThumbs.DataSource = dir.GetFiles("*.bmp");
gridThumbs.DataBind();
}
protected string GetImageUrl(object path)
{
return "Default.aspx?x=50&y=50&FilePath=" +
Server.UrlEncode((string)path);
}
}
File: NextPage.aspx
<%@ Page language="c#" Inherits="ThumbnailViewer" CodeFile="NextPage.aspx.cs" %>
ThumbnailViewer
File: NextPage.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class ThumbnailViewer : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if ((Request.QueryString["X"] == null) ||(Request.QueryString["Y"] == null) ||(Request.QueryString["FilePath"] == null)){
return;
}
int x = Int32.Parse(Request.QueryString["X"]);
int y = Int32.Parse(Request.QueryString["Y"]);
string file = Server.UrlDecode(Request.QueryString["FilePath"]);
Bitmap image = new Bitmap(x, y);
Graphics g = Graphics.FromImage(image);
System.Drawing.Image thumbnail = System.Drawing.Image.FromFile(file);
g.DrawImage(thumbnail, 0, 0, x, y);
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
}
}