I am trying send a image between two device with socketio.I can send pictures, but it takes too long.I use byte array for image transfer.
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
// convert from byte array to bitmap
public static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
I use getImage(return bitmap) for showing.And I use getBytes(from bitmap) for image transfer.
Server log (image byte array) stream of byte array takes too long
so that the transfer process takes too long.Is there a faster solution you know? I use gottox-client on android for socketio.Thanks in advance..
UPDATE
in android:
Message msg = new Message();
msg.setType("IMAGE");
msg.setImage(DbBitmapUtility.getBytes(bmp));
msg.setSender(userName);
msg.setTo(toName);
Gson gson = new Gson();
String json = gson.toJson(msg);
socket.emit("message", json);
in nodejs server:
socket.on('message', function(message) {
users[obj.to].emit('event', message);
//save to mongodb on nodejs
}
on receive in android:
if (event.toString().equals("event")) {
Type listType = new TypeToken<Message>() {
}.getType();
Gson gson = new Gson();
Message message = gson.fromJson(args[0].toString(), listType);
//conditions
mMessages.add(message);
scrollMyListViewToBottom();//notifydatasetChanged
}