W
Web Team @ Borough of Poole
Hi All,
I'm trying to write web form that will be the source of an image tag,
generating an image on the fly.
e.g:
<img src="genimage.aspx">
My code (in genimage.aspx) so far:
'Make sure we always get a fresh image
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = "image/jpg"
'Some vars!
Dim height As Integer = 100
Dim width As Integer = 200
Dim r As New Random
Dim x As Integer = r.Next(75)
'Create an image, over lay some text
Dim bmp As New Bitmap(width, height,
PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp)
g.TextRenderingHint = TextRenderingHint.AntiAlias
g.Clear(Color.Orange)
g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3)
g.DrawRectangle(Pens.Gray, 2, 2, width - 3, height - 3)
g.DrawRectangle(Pens.Black, 0, 0, width, height)
g.DrawString(Request.QueryString("overlaytext"), New
Font("Arial", 12, FontStyle.Italic), SystemBrushes.WindowText, New
PointF(x, 50))
'Save the image to memory and output it
Dim tempStream As New MemoryStream
bmp.Save(tempStream, ImageFormat.Jpeg)
Response.BinaryWrite(tempStream.ToArray())
'Clean up
bmp.Dispose()
g.Dispose()
Response.End()
For some reason, this just doesnt output anything!
Help! Thanks!
I'm trying to write web form that will be the source of an image tag,
generating an image on the fly.
e.g:
<img src="genimage.aspx">
My code (in genimage.aspx) so far:
'Make sure we always get a fresh image
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = "image/jpg"
'Some vars!
Dim height As Integer = 100
Dim width As Integer = 200
Dim r As New Random
Dim x As Integer = r.Next(75)
'Create an image, over lay some text
Dim bmp As New Bitmap(width, height,
PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp)
g.TextRenderingHint = TextRenderingHint.AntiAlias
g.Clear(Color.Orange)
g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3)
g.DrawRectangle(Pens.Gray, 2, 2, width - 3, height - 3)
g.DrawRectangle(Pens.Black, 0, 0, width, height)
g.DrawString(Request.QueryString("overlaytext"), New
Font("Arial", 12, FontStyle.Italic), SystemBrushes.WindowText, New
PointF(x, 50))
'Save the image to memory and output it
Dim tempStream As New MemoryStream
bmp.Save(tempStream, ImageFormat.Jpeg)
Response.BinaryWrite(tempStream.ToArray())
'Clean up
bmp.Dispose()
g.Dispose()
Response.End()
For some reason, this just doesnt output anything!
Help! Thanks!