绘制对象为byte []对象、byte

由网友(故笙诉离歌_)分享简介:我已经从网络中的ImageView的图像。这是非常小的(图标),我想它存储在我的SQLite数据库。我可以从mImageView.getDrawable()被拉伸,但那时我不知道下一步该怎么做。我不完全理解绘制对象类的Andr​​oid。我知道我可以从位图得到一个字节数组,如:位图的DefaultIcon = Bi...

我已经从网络中的ImageView的图像。这是非常小的(图标),我想它存储在我的SQLite数据库。 我可以从mImageView.getDrawable()被拉伸,但那时我不知道下一步该怎么做。 我不完全理解绘制对象类的Andr​​oid。

我知道我可以从位图得到一个字节数组,如:

 位图的DefaultIcon = BitmapFactory.de codeStream(中);

ByteArrayOutputStream流=新ByteArrayOutputStream();
defaultIcon.com preSS(Bitmap.Com pressFormat.JPEG,100,流);

字节[]的BitmapData = stream.toByteArray();
 

但我怎么得到一个字节数组从绘制对象?

解决方案

 绘制对象D组; //提拉(队长明显,营救!)
点阵位图=((BitmapDrawable)D).getBitmap();
ByteArrayOutputStream流=新ByteArrayOutputStream();
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
字节[]的BitmapData = stream.toByteArray();
 

超级列表框增加获取程序图片项目 哔哩哔哩

I have an image from the web in an ImageView. It is very small(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.

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();

But how do I get a byte array from 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();

阅读全文

相关推荐

最新文章