FLIR One Developer / Blog / Topics / Network socket / How to send image via networksocket

How to send image via networksocket

Home Forums Android development Installation and getting started How to send image via networksocket

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Thomas Thomas 1 month, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)

  • Author

    Posts

  • #9270

    Profile photo of Thomas
    Thomas

    Participant

    Hi i would like to know how to send an image via network?</p>
    <p>I got some sample code but i don’t understand it .</p>
    <p>if (streamSocket != null && streamSocket.isConnected()){<br />
    try {<br />
    // send PNG file over socket in another thread<br />
    final OutputStream outputStream = streamSocket.getOutputStream();<br />
    // make a output stream so we can get the size of the PNG<br />
    final ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();</p>
    <p> thermalBitmap.compress(Bitmap.CompressFormat.WEBP, 100, bufferStream);<br />
    bufferStream.flush();<br />
    (new Thread() {<br />
    @Override<br />
    public void run() {<br />
    super.run();<br />
    try {<br />
    /*<br />
    * Header is 6 bytes indicating the length of the image data and rotation<br />
    * of the device<br />
    * This could be expanded upon by adding bytes to have more metadata<br />
    * such as image format<br />
    */<br />
    byte[] headerBytes = ByteBuffer.allocate((Integer.SIZE + Short.SIZE) / 8).putInt(bufferStream.size()).putShort((short)deviceRotation).array();<br />
    synchronized (streamSocket) {<br />
    outputStream.write(headerBytes);<br />
    bufferStream.writeTo(outputStream);<br />
    outputStream.flush();<br />
    }<br />
    bufferStream.close();</p>
    <p> } catch (IOException ex) {<br />
    Log.e(“STREAM”, “Error sending frame: ” + ex.toString());<br />
    }<br />
    }<br />
    }).start();<br />
    } catch (Exception ex){<br />
    Log.e(“STREAM”, “Error creating PNG: “+ex.getMessage());</p>
    <p> }</p>
    <p>For me we only send the header there ? how can we whole image and send it ? i don’t need header btw?

    #9560

    Profile photo of Thomas
    Thomas

    Participant

    Hi can i get an int to know how to send thermal image via socket ?

    #9940

    Profile photo of Ruth
    Ruth

    Participant

    You aren’t closing the socket after you send the image, so the client never stops reading. The server should close the socket output stream, and close the socket itself in a finally block.

    The client should also close his socket, in a finally block.

    #9942

    Profile photo of Ruth
    Ruth

    Participant

    You aren’t closing the socket after you send the image, so the client never stops reading. The server should close the socket output stream, and close the socket itself in a finally block. Official Site

    The client should also close his socket, in a finally block.

    Any update????

    #9944

    Profile photo of Yvette
    Yvette

    Participant

    The problem is that ImageIO aits for the end of the stream. Sockets send it only when you close it How to install FaceTime on PC?.

    #10000

    Profile photo of Thomas
    Thomas

    Participant

    The probleme is that i can’t get the bitmap from GlPreviewactivity.
    So i can’t not send the image.

    The bitmap is only on Previewactivity but i can’t code in this activity because it’s never called.
    I tried to put some log.d in the onStart or onCreat methode but none are displayed.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.