Hi,
I want to send an image using protocol buffer in Java.
Here is my proto:
message Bitmap {
required bytes Bitmap = 1;
required float x = 2; //x position
required float y = 3; //y position
}
Here is my code in the client:
Bitmap bt = BitmapFactory.decodeResource(getResources(), R.drawable.image);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bt.compress(CompressFormat.PNG, 100, baos);
byte[] byteArray = baos.toByteArray();
Protos.Bitmap pbt = Protos.Bitmap.newBuilder()
.setBitmap(ByteString.copyFrom(byteArray))
.setX(x)
.setY(y)
.build();
Here is my code in the server:
byte[] byteArray = req.getBitmap().toByteArray();
Bitmap bt = Bitmap.createBitmap(BitmapFactory.decodeByteArray(
byteArray, 0,
byteArray.length));
x = req.getX();
y = req.getY();
I don't know where the problem is.
I tried also this code in the client:
Protos.Bitmap pbt2 = pbt;
byte[] ba = pbt2.getBitmap().toByteArray();
Bitmap bt2 = BitmapFactory.decodeByteArray(ba, 0, ba.length);
canvas.drawBitmap(bt2,x,y,paint); --> this code is working
anyone has an idea??
Thanks,
Robert