从SQLite数据库使用光标在android的显示图像 [英] Displaying image from the sqlite database using cursor in android

查看:143
本文介绍了从SQLite数据库使用光标在android的显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在的ImageView从SQLite数据库使用光标显示图像。我用低于code检索图像,但我不能够在ImageView的显示图像。

i want to display image in imageview from sqlite database using cursor. i used below code to retrieve image but i am not able to display image in 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); 

比形象,名称和价格将显示,但图像不显示等。 任何建议或code,它会帮助我解决这个问题。

other than image, name and price will display but image will not display. any suggestion or code that will help me to solve this problem.

请帮我。

在此先感谢。

推荐答案

我试着使用,而不是字节数组流,我的例子只是为我工作。 也可以尝试使用Cursor.getColumnIndex()

I've tried to use Stream instead of byte array, mine example simply works for me. Also try to use Cursor.getColumnIndex()

    byte[] blob = c.getBlob(c.getColumnIndex(YourDB.IMAGE));
    ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

下面是我的CREATE TABLE语句,请仔细检查你的

Here's my "create table" statement, pls double check yours

    create table datatable(_id INTEGER PRIMARY KEY AUTOINCREMENT, image BLOB, price INTEGER);

这篇关于从SQLite数据库使用光标在android的显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆