B4J Question Recieve stream picture over internet

YIM bunchhat

Active Member
Licensed User
Longtime User
Hello I wrote a code to receive image over internet. It can connect successfully and got many byte show in Log but it doesn't show image on imageview. If I use browser type host and port, the image is showed successful, Here is my code :
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private ImageView1 As ImageView
    Private client1 As Socket
    Private astream As AsyncStreams
    'Private Pane1 As Pane
    'Private cvs As Canvas
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
    client1.Initialize("client1")
    client1.Connect("proxy70.yoics.net",38901,20000)
    ImageView1.Initialize("ImageView1")
    ImageView1.Enabled = True
    'cvs.Initialize("cvs")
    'Pane1.AddNode(cvs, 0, 0, Pane1.Width, Pane1.Height)
End Sub
Sub client1_Connected (Successful As Boolean)
    If Successful Then
        astream.Initialize(client1.InputStream,client1.OutputStream,"astream")
        Log("connected")
    Else
        Log("Error")
    End If
End Sub
Sub astream_NewData (Buffer() As Byte)
    Dim In As InputStream
    Log(Buffer.Length)
    In.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim img As Image
    img.Initialize2(In)
    ImageView1.SetImage(img)
 
    'Dim bmp As Image
    'bmp.Initialize2(In)
    'cvs.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height)
End Sub
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Do you know the size of the image (in bytes)? Is that the number of bytes being logged in your astream_newData() event? It might be that astream_NewData() is being raised whenever there's new data to report, not necessarily that ALL the data has been received. You may have to create a ByteBuffer object as a global variable and keep appending each new Buffer to it with each new astream_NewData raising until it is complete and then attempt to show the image.
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
I am new with code if possible please give me example or modify my code thank. In Log show the number of byte
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
First, when astream_NewData is raised, it logs the number of bytes received, correct? Is that number of bytes the same number of bytes that you know the image to contain?
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
Yes it log number of byte receive, and the number of byte image I don't know just know resolution 320x240. Step that image work is Webcam provide image to Raspberry and Raspberry transfer image to website sweaved.com. that website provide host and port of that image every 30minute. Then I connect to that host and port I got number of byte in log as told above.
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
I saw it and test good, but it doesn't seem like what I want to. As I tell on Astream I got byte array from host and port of website I use but don't know how do make it become image on my imageview. On your example image show on browser, but I want image show on my app
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
Hi...Erel. What you give me is work over local network. but what I am doing work over internet. The receive byte I got seem content many information of website that provide free host and port so I don't know how to cut it only important information(picture)...Totally if you have sample code how to stream video from webcam to other device (pc or phone) over internet, it is what I wanna do and know.....:'(
 
Upvote 0
Top