You want to display a page of images stored in your database and scaled on the fly to thumbnail format.
Implement the first of the two ASP.NET pages described in Recipe 15.3, changing the
Page_Load method in the code-behind class to scale the full-sized image retrieved from the database to the appropriate size for a thumbnail presentation.
Page_Load method of the code-behind class for the page, use the .NET language of your choice to:
System.Drawing.Image object from the byte array retrieved from the database.
Use a constant to define the height of the thumbnail and calculate the width to maintain the aspect ratio of the image.
GetThumbnailImage method of the
Image object to scale the image to the desired size.
Load the thumbnail image into a
MemoryStream and write it to the
Examples 15-16 and 15-17 show the VB and C# code-behind class for our example that illustrates this solution. (See the CH15ImageFromDatabaseVB .aspx file and VB and C# code-behind files in Recipe 15.3 for our starting point.)
To display the thumbnails, create another ASP.NET page, add a
DataList control with image tags in the
ItemTemplate, and use data binding to set the
src attributes of the image tags.
In the .aspx file for the page:
DataList control to provide the ability to generate a list using data binding.
HeaderTemplate to label the table of images.
ItemTemplate to define an image that is displayed in the ...