我收到错误GDI +中发生了一般错误 在线
bit.Save(str, Imaging.ImageFormat.Png)
请帮助我,这是我的完整代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsNothing(Request.QueryString("id")) = False Then
If Val(Request.QueryString("id")) > 0 Then
Dim dsFiles As New DataSet
dsFiles = oFileData.GetFile(Val(Request.QueryString("id")))
Dim bindata() As Byte = dsFiles.Tables(0).Rows(0).Item("FileData")
Dim str As New MemoryStream
str.Write(bindata, 0, dsFiles.Tables(0).Rows(0).Item("FileSize"))
Dim bit As Bitmap = New Bitmap(str)
Response.ContentType = ".png"
bit.Save(str, Imaging.ImageFormat.Png)
str.WriteTo(Response.OutputStream)
str.Close()
Else
Response.Write("<script language=""javascript"" type=""text/javascript"">window.close();</script>")
End If
Else
Response.Write("<script language=""javascript"" type=""text/javascript"">window.close();</script>")
End If
End Sub
答案 0 :(得分:0)
可能有很多原因 - 可能是字节数组的内容无效的图像数据。实际上,无需创建Bitmap
或MemoryStream
来将图像数据/字节写入响应流。
试试这个,
Dim bindata() As Byte = dsFiles.Tables(0).Rows(0).Item("FileData")
Response.ContentType = "image/png"
Response.BinaryWrite(bindata)
Response.Flush()
Response.End()