Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim outPutFormat As System.Drawing.Imaging.ImageFormat
Dim contType As String
Dim Index As Integer = Request.QueryString("index")
Dim ImageType As String = Request.QueryString("imagetype")
Dim TargetWidth As Integer = 0
If Not Request.QueryString("targetwidth") = Nothing Then
TargetWidth = Request.QueryString("targetwidth")
End If
Select Case ImageType
Case "png"
outPutFormat = System.Drawing.Imaging.ImageFormat.Png
contType = "image/png"
Case "jpg"
outPutFormat = System.Drawing.Imaging.ImageFormat.Jpeg
contType = "image/jpeg"
Case "gif"
outPutFormat = System.Drawing.Imaging.ImageFormat.Gif
contType = "image/gif"
End Select
Dim bytes() As Byte = Session("ImageBytes" & Index)
Session("ImageBytes" & Index) = Nothing
Dim stmMemory As IO.MemoryStream = New IO.MemoryStream(bytes)
If TargetWidth > 0 Then
'Resize
Dim imgThumb As System.Drawing.Image
Dim bm_source As New Bitmap(stmMemory)
Dim scale_factor As Double = TargetWidth / bm_source.Width
Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
Dim myPtr As IntPtr
imgThumb = bm_source.GetThumbnailImage(CInt(bm_source.Width * scale_factor), CInt(bm_source.Height * scale_factor), myCallback, myPtr)
bm_source.Dispose()
stmMemory = New IO.MemoryStream
imgThumb.Save(stmMemory, outPutFormat)
imgThumb.Dispose()
End If
Response.Clear()
Response.ContentType = contType
stmMemory.WriteTo(Response.OutputStream)
Response.End()
End Sub