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
}
// do something with byte[]
Cuando miro el búfer después de que la llamada a copyPixelsToBuffer
los bytes son todos 0 ... El mapa de bits devuelto por la cámara es inmutable ... pero eso no debería importar ya que está haciendo una copia.
¿Qué podría estar mal con este código?
fuente
ByteArrayOutputStream
asignará unbyte[]
tamaño igual a labyte[]
copia de suBitmap
, a continuación,ByteArrayOutputStream.toByteArray()
sin embargo, volverá a asignar otrobyte[]
del mismo tamaño.