Sometimes we need to convert image to bytes to store image into SQL server database.
First of all we have to imports some namespace in our class.
Imports System.IO
Imports
System.IO.Stream
here is vb code for that conversion.
Public Function ConvertImageToByte(ByVal
Img As Image) As
Byte()
Dim ms As MemoryStream = New
MemoryStream()
Img.Save(ms, Img.RawFormat)
Dim
data(ms.Length) As Byte
ms.Position = 0
ms.Read(data, 0, ms.Length)
ms.Close()
ms = Nothing
ConvertImageToByte = data
End Function
Happy Coding.Cheers
Comments
Post a Comment