图形是符号



我有一个Visual Studio 2003应用程序,可以将图形呈现到我的网页上。自从我使用它以来已经有一段时间了,但是我将代码复制并粘贴到一个新的2008 Visual Studio Vb.Net 项目中,并且输出到屏幕上的只是很多符号而不是图形。

我做了一个简短的测试代码,它不起作用。我错过了什么?

    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()

您只是将字节数组写出到响应流中 - 假设默认内容类型为 text/html ,浏览器认为它正在获取 HTML 并将它获得的内容呈现为文本。

输出之前将内容类型更改为image/gif

Response.ContentType = "image/gif"
objBitMap.Save(Response.OutputStream, ImageFormat.Gif)

最新更新