SolvedBytes

Posts 1–5 of 5 · Page 1 of 1
Bytes
Hey there

Wondering if someone can help me with making Image convert to Bytes
thx
Code:
Public Function ConvertImageFiletoBytes(ByVal ImageFilePath As String) As Byte()
            Dim _tempByte() As Byte = Nothing
            If String.IsNullOrEmpty(ImageFilePath) = True Then
                Throw New ArgumentNullException("Image File Name Cannot be Null or Empty", "ImageFilePath")
                Return Nothing
            End If
            Try
                Dim _fileInfo As New IO.FileInfo(ImageFilePath)
                Dim _NumBytes As Long = _fileInfo.Length
                Dim _FStream As New IO.FileStream(ImageFilePath, IO.FileMode.Open, IO.FileAccess.Read)
                Dim _BinaryReader As New IO.BinaryReader(_FStream)
                _tempByte = _BinaryReader.ReadBytes(Convert.ToInt32(_NumBytes))
                _fileInfo = Nothing
                _NumBytes = 0
                _FStream.Close()
                _FStream.Dispose()
                _BinaryReader.Close()
                Return _tempByte
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
http://www.codeproject.com/Articles/31921/Convert-Image-File-to-Bytes-and-Back
Quote Originally Posted by Dragon(H)ell View Post
Hey there

Wondering if someone can help me with making Image convert to Bytes
thx
Quote Originally Posted by DawgiiStylz View Post
Code:
Public Function ConvertImageFiletoBytes(ByVal ImageFilePath As String) As Byte()
            Dim _tempByte() As Byte = Nothing
            If String.IsNullOrEmpty(ImageFilePath) = True Then
                Throw New ArgumentNullException("Image File Name Cannot be Null or Empty", "ImageFilePath")
                Return Nothing
            End If
            Try
                Dim _fileInfo As New IO.FileInfo(ImageFilePath)
                Dim _NumBytes As Long = _fileInfo.Length
                Dim _FStream As New IO.FileStream(ImageFilePath, IO.FileMode.Open, IO.FileAccess.Read)
                Dim _BinaryReader As New IO.BinaryReader(_FStream)
                _tempByte = _BinaryReader.ReadBytes(Convert.ToInt32(_NumBytes))
                _fileInfo = Nothing
                _NumBytes = 0
                _FStream.Close()
                _FStream.Dispose()
                _BinaryReader.Close()
                Return _tempByte
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
http://www.codeproject.com/Articles/31921/Convert-Image-File-to-Bytes-and-Back
Why go to that much effort?
Code:
System****.File.ReadAllBytes("C:\example.jpg")
If you already have an Image instance, you can use an ImageConverter to convert it to bytes.

Code:
Dim img As Image = Nothing '//your image object
Dim imgConverter As New ImageConverter()
Dim imgBytes As Byte() = imgConverter.ConvertTo(img, GetType(Byte()))
Marked Solved. No more posting.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us