In my application Android, I am trying to receive some image from a server with socket, but I can't display them with setImageBitmap(). I don't have any error, but my screen stay white. Here is my code :
public class CommunicateurAndroid implements Runnable {
public CommunicateurAndroid(Socket s, ImageView img) {
_imageV = img;
try {
_din = new DataInputStream(s.getInputStream());
_dout = new DataOutputStream(s.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
new Thread(this).start();
}
public void run() {
int length = 0;
byte tmp;
while (true) try {
length = _din.readInt();
byte tab[] = new byte[length];
for (int i = 0; i < length; i++) {
tmp = _din.readByte();
tab[i] = tmp;
}
_image = BitmapFactory.decodeByteArray(tab, 0, tab.length);
System.out.println("----------");
if (_image != null) {
_imageV.setImageBitmap(_image);
System.out.println("TEST");
Thread.sleep(5000);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public Bitmap get_image() {
return _image;
}
private DataInputStream _din;
private DataOutputStream _dout;
private Bitmap _image;
private ImageView _imageV;
}
I call the constructor with this linenew CommunicateurAndroid(_socket, (ImageView) findViewById(R.id.ImageView3_Left));
Can anybody help me?
0 comments:
Post a Comment