对于之前没做图像处理的,可能对图像处理没啥感觉. 当需要你做图像处理,才发现生无可恋.
1. 已知 bitmap 获取图片的byte[]数据
Bitmap bitmap = BitmapFactory.decodeFile(""); //已知bitmap
int count = bitmap.getByteCount(); //获取bitmap的大小
ByteBuffer byteBuffer = ByteBuffer.allocate(count); //创建图片大小的缓存区
bitmap.copyPixelsToBuffer(byteBuffer); // 将图片复制到缓存区
byte[] byteimage = byteBuffer.array(); //将缓存区的数据复制个byte[]
2.已知bitmap 的 byte[]数据 获取bitmap
byte[] bytesiamge = new byte[1024]; //已知图片数据
Bitmap bitmap1 = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888); //创建bitmap
ByteBuffer byteBuffer1 = ByteBuffer.wrap(bytesiamge); //将byte[]数据转换成bytebuffer数据
bitmap1.copyPixelsFromBuffer(byteBuffer1); //将bytebuffer数据转换成bitmap