Problem with BC.ArrayCopy

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey everyone,

I have a problem with BC.ArrayCopy.
So I want to send a bytearray with B4A over a bluetooth (asyncstream) connection to another device.

This is my code:

B4X:
Sub Camera1_PreviewTaken (PictureFrame() As Byte)
   Log("Preview Taken")
   CurrentJPEG = PictureFrame
   If connected Then
      If AStreams.IsInitialized = False Then Return
         Astreams.Write(AddCommandToBytes(IMAGE_BYTE, CurrentJPEG, CurrentJPEG.Length))
           Log("Sending: Image ")
   Else
      Msgbox("You are not connected.","Connection")
   
    End If
   
End Sub

Sub AddCommandToBytes(Command As Byte, Buffer() As Byte, Length As Int) As Byte()
   Dim b(Length + 1) As Byte
   b(0) = Command
   BC.ArrayCopy(Buffer, 0, b, 1, Length)
   Return b
End Sub

Sub AStreams_NewData (Buffer() As Byte)

   Dim command As Byte
   command = Buffer(0)
   Select command
      Case TEXT_BYTE
         Dim msg As String
          msg = BytesToString(Buffer, 1, Buffer.Length-1, "UTF8")
          Msgbox(msg, "")
      Case IMAGE_BYTE
         Dim b() As Byte
         BC.ArrayCopy(Buffer, 1, b, 0, Buffer.Length-1)
         Camera1.uploadFrame(b, "http://www.mywebsite.net/index.php")
   End Select
   
End Sub

Ok, So on my device 1, a preview is taken and send to the other device. Everything seems to work until arrived in Case IMAGE_BYTE. BC.ArrayCopy.

So I copy the array received from the buffer and put it into a new array b starting from byte(0).

Why doesn't this work. :confused:

I get an error array out of bounds.
BC is byteconverter

XverhelstX
 
Top