0

エラーが表示されます A general error occurred in GDI+
on line

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
4

1 に答える 1

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()
于 2012-08-14T12:31:52.957 に答える