0
我嘗試將圖像從mssql varbinary(max)列導入到iTextSharp。 但它總是顯示了錯誤「的NullReferenceException」「phrase.Add(imageChunk)」將二進制轉換爲圖像的錯誤
我的代碼是:
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
Dim q As String = "select top 1 pic_id from pic"
Dim cmd As SqlCommand = New SqlCommand(q, conn)
conn.Open()
Dim sr As SqlDataReader = cmd.ExecuteReader
While sr.Read
Dim byt() As Byte = CType(sr.Item("pic_id"), Byte())
Dim ms As MemoryStream = New MemoryStream(byt)
Dim sdi As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
Dim img As Image = Image.GetInstance(sdi, ImageFormat.Jpeg)
Dim imageChunk As Chunk = New Chunk(img, 0, 0)
phrase.Add(imageChunk)
End While
該列的數據類型爲「VARBINARY(最大)」和數據是這樣的:(0x89504E470D0A1A0A0000000D494 ....................)