可绘制为byte [] [英] Drawable to byte[]
本文介绍了可绘制为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网络上有一个 ImageView
的图片。它是非常小的(favicon),我想把它存储在我的SQLite数据库。
我可以从 mImageView.getDrawable()
获得可绘制
,但是我不知道做下一步。我不完全理解Android中的 Drawable
类。
I have an image from the web in an ImageView
. It is very small (a favicon) and I'd like to store it in my SQLite database.
I can get a Drawable
from mImageView.getDrawable()
but then I don't know what to do next. I don't fully understand the Drawable
class in Android.
我知道我可以从一个字节数组 Bitmap
like:
I know I can get a byte array from a Bitmap
like:
Bitmap defaultIcon = BitmapFactory.decodeStream(in);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
但是如何从 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();
这篇关于可绘制为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文