Android Question problem load bitmap with byte() tcp

hi i send image with c# server to b4a tcp client and after get error load bitmap error.

this code very good work for udp just error in tcp from b4a i think problem for tcp b4a




server code c#:
            img = Image.FromFile(@"C:\Users\at\Pictures\download.jpeg");
            ms = new MemoryStream();
            bmp.Save(ms, ImageFormat.Jpeg);
            byte[] byteArray = ms.ToArray();
            reci = byteArray.Length.ToString();
            nwStream.Write(byteArray, 0, byteArray.Length);



client code b4a:
Sub img (buffer() As Byte)
   

    Dim in As InputStream
    in.InitializeFromBytesArray(buffer, 0, buffer.Length)
    Dim bmp As Bitmap
    bmp.Initialize2(in)
    Dim bd As BitmapDrawable
    bd.Initialize(bmp)
    bd.Gravity = Gravity.FILL
    Panel3.Background = bd
   
    in.Close
End Sub



errors:
screen_second_img (java line: 411)
java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:539)
at io.hanitum.screen_second._img(screen_second.java:411)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
at io.hanitum.tcp._astream_newdata(tcp.java:162)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7565)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

java.lang.RuntimeException: Error loading bitmap.
 
Of course not.

Don't assume that the complete image will arrive as a single packet. It won't.
Either switch to AsyncStreams in prefix mode or collect the data yourself with B4XBytesBuilder


Thank you very much for your answer. I am building a very big project and I preferred to write it with b4a.
 
Upvote 0
Of course not.

Don't assume that the complete image will arrive as a single packet. It won't.
Either switch to AsyncStreams in prefix mode or collect the data yourself with B4XBytesBuilder.


I tried and used the methods you mentioned, but neither sound nor image was received

I tried mjpeg or udp and tcp or any other method but they do not work the only way is a real time connection with b4a.

When I enable the prefix mode in tcp, after receiving the first byte, the connection is automatically disconnected

This issue is very important to me. I have to receive and display 60 images every second. Also, the sound must be clearly received. The server is under Windows c#. I'm glad you if can help with example code b4a.
 
Upvote 0
Start with this example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator


It will be difficult to receive 60 fps of separate images. You will need to use a video encoding for such rate.
Hello, good day, yes, I tried this method and b4a strangely cuts the connection after receiving information from a b4j program. For example, my server is in C #, it is only responsible for sending text, but when sending data such as photos .... The connection be broken. I tried to send the information in 100 bytes, but unfortunately in perfix mode this will happen.

I have a game page directly, I can stream it, and this can not be done directly with video, it is only possible with photos.
 
Upvote 0
Top