/** 方法一
* 将bitmap转为数组的方法
*
* @param bitmap 图片
* @return 返回数组
*/
public byte[] getBytesByBitmap(Bitmap bitmap) {
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
return buffer.array();
}
/** 方法二
* 将bitmap转为数组的方法
*
* @param bitmap 图片
* @return 返回数组
*/
public byte[] getBytesByBitmaps(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bitmap.getByteCount());
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
return outputStream.toByteArray();
}
/** 方法三
* 其中w和h你需要转换的大小
* path转换为bitmap:上面方法即可;
* imageview获取drawable并转换为 bitmap :Bitmap bt= ((BitmapDrawable) mImageview.getDrawable()).getBitmap();
* resourceid转换为bitmap:Bitmap bt = BitmapFactory.decodeResource(getResources(), R.drawable.resourceid);
*
android开发之bitmap转数组的方法
最新推荐文章于 2024-07-09 21:52:34 发布
本文详细介绍了在Android开发中如何将Bitmap图像转换为Byte数组的步骤和方法,包括使用Bitmap的compress方法和ByteBuffer进行转换,以及在处理大量图片时的性能考虑。
摘要由CSDN通过智能技术生成