我有一张来自网络的图像ImageView
。它非常小(一个图标),我想将它存储在我的 SQLite 数据库中。
我可以得到一个Drawable
from mImageView.getDrawable()
但我不知道下一步该做什么。我不完全理解Drawable
Android 中的类。
我知道我可以从 a 获取字节数组Bitmap
like:
Bitmap defaultIcon = BitmapFactory.decodeStream(in);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
但是我如何从 a 中获取字节数组Drawable
?
Drawable d; // the drawable (Captain Obvious, to the rescue!!!)
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)