<% ' import all relevant namespaces %>
<%@ Page Language="VB" Debug="true" %>
<%@ import namespace="System" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>
<%@ import namespace="System.IO" %>

<script runat="server">
Dim imageWidth = 640
Dim imageHeight = 480

Sub Page_Load(s as object, e as eventargs)
Try
dim g as System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath("Img/Golfd.jpg"))

dim thisFormat=g.rawformat
dim imgOutput as New Bitmap(g, NewthumbSize(imageWidth,imageHeight))
if thisformat.equals(system.drawing.imaging.imageformat.Gif) then
response.contenttype
="image/gif"
else
response.contenttype
="image/jpeg"
end if
imgOutput.save(response.outputstream, thisformat)
g.dispose()
imgOutput.dispose()
Catch
Call sendError()
End Try
End Sub


Function NewthumbSize(currentwidth, currentheight)
dim tempMultiplier as Double
if currentheight > currentwidth then
tempMultiplier
= 300 / currentheight
Else
tempMultiplier
= 300 / currentwidth
end if
dim NewSize as New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
return NewSize
End Function


Sub sendError()
dim imgOutput as New bitmap(120, 30, pixelformat.format24bpprgb)
dim g as graphics = graphics.fromimage(imgOutput)
g.clear(color.yellow)
g.drawString(
"Wrong£¡", New font("黑体",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2))
response.contenttype
="image/gif"
imgOutput.save(response.outputstream, imageformat.gif)
g.dispose()
imgOutput.dispose()
end sub

</script>