我想使用光标在 sqlite 数据库的 imageview 中显示图像。我使用下面的代码来检索图像,但我无法在 imageview 中显示图像。
Cursor c=this.db.query(TABLE_NAME, new String[] { "name","price","image" },
null, null, null, null, null);
name.setText(c.getString(0));
price.setText(c.getString(1));
byte b[]=c.getBlob(2);
Bitmap bp=BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image=(ImageView)findViewById(R.id.ImageView);
//ByteArrayInputStream imageStream = new ByteArrayInputStream(b);
//Bitmap theImage = BitmapFactory.decodeStream(imageStream);
//image.setImageBitmap(theImage);
image.setImageBitmap(bp);
除图像外,还会显示名称和价格,但不会显示图像。
任何可以帮助我解决这个问题的建议或代码。
请帮我。
提前致谢..
我尝试使用 Stream 而不是字节数组,我的示例对我来说很有效。
还尝试使用 Cursor.getColumnIndex()
byte[] blob = c.getBlob(c.getColumnIndex(YourDB.IMAGE));
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
这是我的“创建表”语句,请仔细检查你的
create table datatable(_id INTEGER PRIMARY KEY AUTOINCREMENT, image BLOB, price INTEGER);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)