mercredi 23 avril 2014

Bitmap to Byte[] coversion


Vote count:

0




I am not new to bitmaps nor new to java. I am trying to convert High resolution bitmaps to byte array in a loop. Please find code here:



ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, stream);
imageByteArray = stream.toByteArray();


When i am using the above approach I cam able to convert 5 images in 1 second. But I need it to be even faster. I tried ByteBuffer approach also like this:



Bitmap bmp = intent.getExtras().get("data");
int size = bmp.getRowBytes() * bmp.getHeight();
ByteBuffer b = ByteBuffer.allocate(size);

bmp.copyPixelsToBuffer(b);

byte[] bytes = new byte[size];

try {
b.get(bytes, 0, bytes.length);
} catch (BufferUnderflowException e) {
// always happens
}


But this is very slow (Slower then previous) :(


Please, can somebody give a faster method? Guide Me...



asked 38 secs ago






Aucun commentaire:

Enregistrer un commentaire