public byte[] getBitmapByte(Drawable drawalbe) {
BitmapDrawable db = (BitmapDrawable) drawalbe;
Bitmap bitmap = db.getBitmap();
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return out.toByteArray();
}
getBitmapByte
最新推荐文章于 2025-03-27 15:01:29 发布
本文介绍了一种将Drawable对象转换为字节数组的方法。通过使用BitmapDrawable和Bitmap类,该方法能有效压缩图片为PNG格式,并将其保存到字节数组中,便于在网络上传输。
2351

被折叠的 条评论
为什么被折叠?



