Imports System.IO Imports System.Drawing Public Class ImageEmitter Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'QueryStrings: ID - Primary Key value ' Key - Primary Key column name ' Source - Table or View that contains the image ' Field - Column that contains the image ' Type - MIME type of the image (gif, jpeg, bmp, tiff ' Height - (optional) Height to scale the image ' Width - (optional) Width to scale the image Dim ID As String = Request.QueryString("ID") Dim Key As String = Request.QueryString("Key") Dim Source As String = Request.QueryString("Source") Dim Field As String = Request.QueryString("Field") Dim ImageHeight As Integer = CInt(Request.QueryString("Height")) Dim ImageWidth As Integer = CInt(Request.QueryString("Width")) Dim dr As SqlDataReader = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings(Server.MachineName), CommandType.Text, _ "SELECT " & Field & " FROM " & Source & " WHERE " & Key & "=" & ID) If Not dr Is Nothing Then dr.Read() Dim FullSizeData() As Byte = dr.GetValue(0) dr.Close() Dim FullSizeImage As System.Drawing.Image FullSizeImage = Image.FromStream(New MemoryStream(FullSizeData)) ' Determine the image format and MIME content-type Dim SourceImageBitmap As New Bitmap(FullSizeImage) Dim SourceImageFormat As Imaging.ImageFormat = SourceImageBitmap.RawFormat SourceImageFormat = Imaging.ImageFormat.Jpeg If SourceImageFormat.Equals(Imaging.ImageFormat.Bmp) Then Response.ContentType = "image/x-ms-bmp" ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Gif) Then Response.ContentType = "image/gif" ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Jpeg) Then Response.ContentType = "image/jpeg" ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Png) Then Response.ContentType = "image/x-png" ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Tiff) Then Response.ContentType = "image/tiff" End If ' Scale the image if requested If ImageHeight > 0 And ImageWidth > 0 And (FullSizeImage.Height > ImageHeight Or FullSizeImage.Width > ImageWidth) Then Dim dummyCallBack As Image.GetThumbnailImageAbort dummyCallBack = New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) Dim ThumbNailImage As Image ThumbNailImage = FullSizeImage.GetThumbnailImage(ImageWidth, ImageHeight, dummyCallBack, IntPtr.Zero) ThumbNailImage.Save(Response.OutputStream, SourceImageFormat) Else FullSizeImage.Save(Response.OutputStream, SourceImageFormat) End If End If End Sub Function ThumbnailCallback() As Boolean Return False End Function End ClassAs a side benefit, GetThumbnailImage does a much better job scaling down an image than Internet Explorer. I.e. the scaled image looks a lot better.
><IMG HEIGHT="80%" src="../images/01cPreparation.jpg" border="0" alt="01cPreparation">>