I have a client application on Android and server on C#, they communicate through a socket. On request server send an image converted to byte[], but how to decode it again on my device into image?
I've already found this code:
Bitmap bmp=BitmapFactory.decodeByteArray(b,0,b.length);
image.setImageBitmap(bmp);
And here's part of client's code:
private void connectSocket(String a){
try {
InetAddress serverAddr = InetAddress.getByName("192.168.1.2");
Socket socket = new Socket(serverAddr, 4444);
BufferedReader in = null;
try {
out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println(message);
String text = "";
image = (ImageView)findViewById(R.id.imageView1);
while ((text = in.readLine()) != null) {
byte[] b = in.readLine().getBytes();
Bitmap bmp=BitmapFactory.decodeByteArray(b,0,b.length);
image.setImageBitmap(bmp);
}
} catch(Exception e) {
Log.e("TCP", "S: Error", e);
} finally {
socket.close();
}
} catch (UnknownHostException e) {
Log.e("TCP", "C: UnknownHostException", e);
e.printStackTrace();
} catch (IOException e) {
Log.e("TCP", "C: IOException", e);
e.printStackTrace();
}
}
So how to get the exact recieved bytes to convert them in an image?