Creating and writing a BitMap

  • Thread starter Web Team @ Borough of Poole
  • Start date
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! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top