android - why Bitmap convert to byte[] will cause size increase? -
i have funtion compress bitmap below 32k. when got returned bitmap, converted byte[], size increased. code demo below, output :
before: 30
after: 85
did use bitmap in wrong way?
bytearrayoutputstream baos = new bytearrayoutputstream(); image.compress(bitmap.compressformat.jpeg, 100, baos); int options = 100; while (baos.tobytearray().length / 1024 > 31 && (count++ < 8)) { // compress below 32k baos.reset(); options -= 10; image.compress(bitmap.compressformat.jpeg, options, baos); } bytearrayinputstream isbm = new bytearrayinputstream(baos.tobytearray()); bitmap bitmap = bitmapfactory.decodestream(isbm, null, null); ll.d("before: " + (baos.tobytearray().length/1024)); // here return bitmap; bytearrayoutputstream output = new bytearrayoutputstream(); bitmap.compress(bitmap.compressformat.jpeg, 100, output); ll.d("after: " + (output.tobytearray().length/1024));
Comments
Post a Comment