1: Dim ImageData as new ImageEntities
2: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
3: 'Split the File Name out to get the information we need
4: Dim ImageInfo As String() = Context.Items("imagename").ToString.Split("-")
5:
6: 'In this example I am only accessing one data source, you could access many,
7: 'add a Select Case with the Image Type and select from other areas
8: Dim ImageType As String = ImageInfo(0)
9:
10: 'We need the ID of the image
11: Dim ImageID As Integer = ImageInfo(1)
12:
13: 'We need to know what size to change it to
14: Dim ImageSize As String = ImageInfo(2)
15:
16: Dim Images As ImageModel.Images
17: Images = ShoppingData.Images.FirstOrDefault( _
18: Function(i As Images) i.ImageID = ImageID)
19:
20: 'Cast the Image data from the database to a Byte()
21: Dim aryContent As Byte() = DirectCast(Images.Image, Byte())
22:
23: 'Create a new Memory Stream to hold the contents of the
24: 'image in ready for the Drawing.Image
25: Dim imgStream As New IO.MemoryStream
26:
27: Dim dummyCallBack As GetThumbnailImageAbort
28: dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort( _
29: AddressOf ThumbnailCallback)
30:
31: imgStream.Write(aryContent, 0, aryContent.Length)
32:
33: Dim Img As System.Drawing.Image
34: Img = Drawing.Image.FromStream(imgStream)
35:
36: 'Set the MIME tyoe
37: Response.ContentType = "image/jpeg"
38: 'Resize the image if we need to
39: If ImageSize = "T" Then
40: 'This will keep the image 100px high and change the width to keep the
41: 'ratio correct
42: Dim ratio = Img.Width / Img.Height
43: Dim height = 100
44: Dim width = 100 * ratio
45: Dim thumbnail As Drawing.Image = Img.GetThumbnailImage( _
46: width, height, dummyCallBack, IntPtr.Zero)
47: thumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
48: ElseIf ImageSize = "S" Then
49: 'This will keep the image 100px wide and change the height to keep the
50: 'ratio correct
51: Dim ratio = Img.Height / Img.Width
52: Dim height = 100 * ratio
53: Dim width = 100
54: Dim thumbnail As Drawing.Image = Img.GetThumbnailImage(width, height, _
55: dummyCallBack, IntPtr.Zero)
56: thumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
57: Else
58: Img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
59: End If
60: Response.End()
61: End Sub