bitmap->byte
创建一个ByteBuffer用于接收数据。首先需要为ByteBuffer开辟内存空间,内存空间的大小就是图片的大小。将bitmap的数据写入ByteBuffer,然后调用ByteBuffer的 array() 方法得到byte。
int bytes = bmp.getByteCount();
ByteBuffer buf = ByteBuffer.allocate(bytes);
bmp.copyPixelsToBuffer(buf);
byte[] byteArray = buf.array();
byte->bitmap
Bitmap bitmap= Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(ByteBuffer.wrap(byteArray));
imageView.setImageBitmap(bitmap);