I had a Visual Studio 2003 application that would render graphics to my web page. It’s been a while since I used it, but I copied and pasted the code to a new 2008 Visual Studio Vb.Net project and the output to the screen is just a lot of symbols instead graphics.
I did a short test code and it won’t work. What am I missing?
Dim X As Integer = 0
Dim Y As Integer = 0
'Build a BitMap that will act as the pallet and container
Dim objBitMap As New Bitmap(360, 360)
'Declare your Graphics objects for painting graphics on your newly created bitmap.
Dim objGraphics As Graphics
objGraphics = Graphics.FromImage(objBitMap)
objGraphics.Clear(Color.White)
objGraphics.DrawLine(New Pen(Color.Red), 0, 0, 200, 200)
objBitMap.Save(Response.OutputStream, ImageFormat.Gif)
objBitMap.Dispose()
objGraphics.Dispose()
You are just writing out the byte array to the response stream – assuming the default content type of
text/html, the browser thinks it is getting HTML and is rendering what it gets as text.Change the content type to
image/gifbefore outputting: