I would like to convert an instance of Bitmapto an instance of ByteArrayin order to be able to pass it to a Webservice.
Right now, what I’m doing is:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] imageData = bos.toByteArray();
ByteArrayBody byteArrayBody = new ByteArrayBody(imageData, imagePath);
The problem here, is that I am using compression to make it happen, and this results in lowering the quality of the bitmap.
Is there any other way to do this?
Thanks!
EDIT:
I can’t compress to PNG, since the server uses JPEG.
getPixels().copyPixelsToBuffer(), which youcan later convert to a byte[].
In any case png compression is the best solution as it does not need as many intermediary operations and gives a compressed result.