今天作一个应用,新增一笔记录到sqlite中去,
记录中有一个字段是一个图像,在新增界面中我用的是imageview控件,点击弹出一个对话框,列出可供选择的图像,单击选择,可是提交后图像显示不正确,只显示一个黑框,个人代码是这样的
java
Java代码 web
Bitmap image = Bitmap.createBitmap(imageView.getDrawable(). .....);sql
从imageview的Drawable里取出信息构造一个bitmap,事实证实是行不通的。ui
[java] view plaincopyspa
Bitmap image = Bitmap.createBitmap(imageView.getDrawable(). .....); .net
从imageview的Drawable里取出信息构造一个bitmap,事实证实是行不通的。 orm
搜索了一下怎么把ImageView转换成Bitmap,发现网上提供一种方法:
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
我试了一下,成功是成功了,可是获得的bitmap大小不对,本来很大的,放到列表里显示得超小,不是我想要的结果。
后来试了一下:
sqlite
Java代码blog
Bitmap image = ((BitmapDrawable)imageView.getDrawable()).getBitmap();get
[java] view plaincopy
Bitmap image = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
成功搞定。