Search code examples
androidinputstreamandroid-storage

Opening a PNG File from Memory and Send Through TCP Sockets


I am looking to send an image from my android device to a computer / raspberry pi running python. I have already achieved a communication from my windows laptop (running a java client) using the following code.

BufferedImage image = ImageIO.read (new File("C:/Users/****/OneDrive/Pictures/Om-nom.png"));
s = new Socket("192.168.2.69",8000);
ImageIO.write(image, "png", s.getOutputStream());
s.close();

However, the BufferedImage library (java.awt.image) is not supported on android. How can I achieve something similar in android studio to run on my android device i.e. read a PNG file from the memory on my device into a byte buffer that can then be sent to a server PC.

Note: The location of my file would be similar to the following /storage/emulated/0/Downloads/frog-face_1f438.png


Solution

  • Thanks for your help Gleichmut. I have managed to write some working code that is available on GitHub if anyone needs similar functionality in their app (sending images through TCP sockets).

    GitHub Repository Here: https://github.com/Lime-Parallelogram/Sending-Images-Through-Sockets-Android-to-Python-

    Note: My code on GitHub includes a python server and a java client designed to run on android - written in Android-Studio