嗨我想將圖像轉換爲字節數組傳遞到SQL作爲字節()。我試着去使用圖像轉換器,但它一直未能如何將System.Drawing.Image轉換爲字節數組?
Dim converter As New ImageConverter
nRow.Signature = converter.ConvertTo(imgSignature, TypeOf(Byte())
我不斷收到錯誤字節是一種不表達
嗨我想將圖像轉換爲字節數組傳遞到SQL作爲字節()。我試着去使用圖像轉換器,但它一直未能如何將System.Drawing.Image轉換爲字節數組?
Dim converter As New ImageConverter
nRow.Signature = converter.ConvertTo(imgSignature, TypeOf(Byte())
我不斷收到錯誤字節是一種不表達
的VB.NET typeof運算符不去做你認爲它。有些混淆可能是由於C#typeof
運營商。 VB.NET等價物是GetType()函數。這工作正常:
Dim converter As New ImageConverter
nRow.Signature = converter.ConvertTo(imgSignature, GetType(Byte())
類型轉換器使用一個MemoryStream使用PNG圖像格式進行轉換。
可以使用MemoryStream
。通過將圖像保存爲MemoryStream
,可以從圖像獲取數據的字節數組:
Dim ms = new MemoryStream()
imgSegnature.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) ' Use appropriate format here
Dim bytes = ms.ToArray()
謝謝你,對我很有幫助。 –