Convert Image to binary format?
Are you looking for sample code to convert image to binary format in VB.NET? Here is an example.
This code used to convert image into binary format
for ex
dim img as image =image.fromfile("C:\test.jpeg")
dim value as string =imageconversion(img)
Public Function ImageConversion(ByVal image As System.Drawing.Image) As String
If image Is Nothing Then Return ""
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif)
Dim value As String = ""
For intCnt As Integer = 0 To memoryStream.ToArray.Length - 1
value = value & memoryStream.ToArray(intCnt) & ","
Next
Return value
End Function
Many thanks for the good code. I faced a small issue, because i needed a byte array, then i do not know how to code a function which sends an array, then i slightly changed this, can u add this also so that others may get benefit from this.
Dim Img As Image = Image.FromFile(OpenFileDialog1.FileName)
Dim SomeBytAry() As Byte
Call ImageConversion(Img, SomeBytAry)
ImageDataSet.ImageTable.AddImageTableRow(SlNoCnt, SomeBytAry)
Public Sub ImageConversion(ByVal image As System.Drawing.Image, ByRef BytAry() As Byte)
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
ReDim Preserve BytAry(memoryStream.ToArray.Length - 1)
For intCnt As Integer = 0 To memoryStream.ToArray.Length - 1
BytAry(intCnt) = memoryStream.ToArray(intCnt)
Next
End Sub
Thanks once again.