1 Imports System
2 Imports System.Web
3 Imports System.IO
4 Imports System.Drawing
5 Imports System.Drawing.Imaging
6
7 Public Class GetImages : Implements IHttpHandler
8
9 Public Sub ProcessRequest(ByVal ctx As HttpContext) Implements IHttpHandler.ProcessRequest
10 'Create the request object and retrieve the QueryString Parameters
11 Dim req As HttpRequest = ctx.Request
12 Dim iRecID As Integer = CType(req.QueryString("RecID"), Integer)
13 Dim sPicSize As String = CType(req.QueryString("Size"), String)
14 Dim img() As Byte = GetData(iRecID, sPicSize)
15 ctx.Response.ContentType = "image/gif"
16
17 If (Not (img) Is Nothing) Then
18 Dim m As MemoryStream = New MemoryStream(img)
19 Dim image As Image = System.Drawing.Image.FromStream(m)
20 image.Save(ctx.Response.OutputStream, ImageFormat.Gif)
21 End If
22
23 End Sub
24
25 Public Function GetData(ByVal iRecID As Integer, ByVal sPicSize As String) As Byte()
26
27 Dim cnn As Data.SqlClient.SqlConnection
28 Dim cmd As Data.SqlClient.SqlCommand
29 Dim msTemp As New MemoryStream
30 Dim strSQL As String
31
32 Select Case sPicSize
33 Case "Large"
34 strSQL = "SELECT LargeImage FROM cyb_Frames WHERE RecID=" & iRecID
35 Case "Small"
36 strSQL = "SELECT Thumbnail FROM cyb_Frames WHERE RecID=" & iRecID
37 Case "Model"
38 strSQL = "SELECT ImageWithModel FROM cyb_Frames WHERE RecID=" & iRecID
39 Case Else
40 strSQL = "SELECT LargeImage FROM cyb_Frames WHERE RecID=" & iRecID
41 End Select
42
43 Dim connString As String = Web.Configuration.WebConfigurationManager.ConnectionStrings("xyz").ConnectionString
44 cnn = New Data.SqlClient.SqlConnection(connString)
45 cmd = New Data.SqlClient.SqlCommand(strSQL, cnn)
46 cnn.Open()
47
48 Return cmd.ExecuteScalar
49
50 End Function
51
52 Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
53 Get
54 Return False
55 End Get
56 End Property
57
58 End Class