我有一个 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)
关于vb.net - 图形是符号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11318120/