I have a ByteBuffer, and I need to add its content to a POST request in order to remotely display the image which represents; but I can't figure it out how to do it.
Doing this doesn't work:
byteBuffer.array()
I have tried to convert it to an array of bytes, but it didn't work because the image wasn't showing properly:
byte[] byteArray = new byte[byteBuffer.remaining()];
frame.duplicate().get(byteArray);
HttpResponse response = null;
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URL);
post.setEntity(new ByteArrayEntity(byteArray));
Also I've think about converting it to an image and get its array of bytes but I don't know how to do it and if it would work...
Any help will be appreciate.
private static byte[] getByteArrayFromByteBuffer(ByteBuffer byteBuffer) {
byte[] bytesArray = new byte[byteBuffer.remaining()];
byteBuffer.get(bytesArray, 0, bytesArray.length);
return bytesArray;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With