Results 1 to 15 of 15

Thread: [RESOLVED] String Array to Byte Array conversion

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2014
    Posts
    32

    Resolved [RESOLVED] String Array to Byte Array conversion

    Hi, I have array converting problem which is in use of Image processing unit.

    I got a PictureBox image convert to byte array.

    Code:
    Dim img as image = Picturebox1.Image
    Dim ms = New MemoryStream()
    img.Save(ms, Imaging.ImageFormat.Jpeg) ' Use appropriate format here
    Dim bytes = ms.ToArray()
    And this "bytes" array, I convert to string array with "," delimiter, for send via TCP connection.

    Code:
    Dim msg = String.Join(",", bytes)
    Now I have all string which converted from byte array with "," delimiter. Like this:
    "217,0,1,10,215,128,104,....."

    And I have to change this string to byte array again in order to convert image format.

    Code:
    Function StringToImage(Byval msg as String) as Image
    
       Dim Bytes As New List(Of Byte)
       Dim message() As String = msg.Split(",")
    
       For i As Integer = 0 To UBound(message)
            Bytes.Add(CByte(message(i)))
       Next
    
       Return CType(Image.FromStream(New IO.MemoryStream(Bytes.ToArray)), Image)
    
    End Function
    Everything is Ok, except For...Next loop at StringToImage function, it takes much time.

    I send this string to server via TCP/IP and server relay string to corresponding client,
    it takes only 0.4sec for 400KB jpeg file but this for..next loop takes like 0.5 sec more.

    Is there any fastest way to convert string array to byte array?
    I saw some article which use;

    Dim Bytes() As Byte = Array.ConvertAll(Of String, Byte)(message, Function(strHold) Convert.ToByte(strHold, 16))

    Like this, but I try and got error only.
    Important thing is, this string array only contains numbers, which must convert to byte accordingly,
    because this string array is converted from Image -> byte array -> string array.
    Anybody can help me out?
    Last edited by stephenpark; Sep 29th, 2014 at 04:00 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width