Reputation: 30385
I would like to convert an instance of Bitmap
to an instance of ByteArray
in 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
.
Upvotes: 0
Views: 3073
Reputation: 31846
getPixels()
.copyPixelsToBuffer()
, which you
can 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.
Upvotes: 3