Thread: Bytes

Results 1 to 5 of 5
  1. #1
    Dragon(H)ell's Avatar
    Join Date
    Nov 2011
    Gender
    male
    Posts
    703
    Reputation
    154
    Thanks
    4,819
    My Mood
    Angelic

    Bytes

    Hey there

    Wondering if someone can help me with making Image convert to Bytes
    thx

  2. #2
    DawgiiStylz's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Dawg House
    Posts
    7,811
    Reputation
    219
    Thanks
    2,896
    My Mood
    Tired
    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
    https://www.codeprojec*****m/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

  3. #3
    Broderick's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    Basement.
    Posts
    100
    Reputation
    42
    Thanks
    30
    Quote Originally Posted by Dawgy Dawg 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
    https://www.codeprojec*****m/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()))
    The fish trap exists because of the fish.
    Once you've gotten the fish you can forget the trap.
    The rabbit snare exists because of the rabbit.
    Once you've gotten the rabbit, you can forget the snare.
    Words exist because of meaning.
    Once you've gotten the meaning, you can forget the words.
    Where can I find a man who has forgotten words so I can talk with him?

  4. #4
    Dragon(H)ell's Avatar
    Join Date
    Nov 2011
    Gender
    male
    Posts
    703
    Reputation
    154
    Thanks
    4,819
    My Mood
    Angelic
    Thanks

    /req close

  5. #5
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Marked Solved. No more posting.

Similar Threads

  1. [Tut]How To NOP Addresses At The Proper Byte Length
    By radnomguywfq3 in forum WarRock - International Hacks
    Replies: 5
    Last Post: 01-08-2008, 05:56 PM
  2. Converting Assembly Into Bytes
    By radnomguywfq3 in forum Visual Basic Programming
    Replies: 0
    Last Post: 09-24-2007, 04:42 PM
  3. Byte values please?
    By Jeckels in forum WarRock - International Hacks
    Replies: 6
    Last Post: 05-01-2007, 03:01 PM
  4. Dark Byte = BUSTED
    By -[standoff]- in forum General
    Replies: 1
    Last Post: 01-04-2007, 07:10 PM
  5. Differences in Bytes.
    By Dave84311 in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 01-02-2006, 12:36 PM