2012-07-26 42 views
0
//MyOpenHelper class 


public static final String TABLE_NAME2 = "Catlog_Chield"; 
db.execSQL("CREATE TABLE IF NOT EXISTS "+TABLE_NAME2+" (_id INTEGER PRIMARY KEY AUTOINCREMENT,log_desc TEXT,log_date TEXT,log_image BLOB,cat_id INTEGER,FOREIGN KEY (cat_id) REFERENCES "+TABLE_NAME1+"(_id))"); 

//My working class 


ByteArrayInputStream inputStream = 
    new ByteArrayInputStream(c.getBlob(c.getColumnIndex(log_image))); //Here I can't give my column name log_name 
    Bitmap bp=BitmapFactory.decodeStream(inputStream); 

    image.setImageBitmap(bp); 

回答

0

请尝试这种方式获取图像:

byte[] image_bytes = c.getBlog(c.getColumnIndex(Here you need to give index)); 
    ByteArrayInputStream inputStream = 
    new ByteArrayInputStream(image_bytes); 
    Bitmap bp=BitmapFactory.decodeStream(inputStream); 

//现在设置使用setImageBitmap方法

+0

像我得到异常 产生的原因:android.database。 CursorIndexOutOfBoundsException:请求索引-1,大小为0 – Mohsin 2012-07-27 12:16:21

+0

由于此时光标位于-1索引处,因此需要使用其方法将光标移动到第一行。像这样if(c.moveToNext()){那么你的代码在里面} – moDev 2012-07-27 14:52:50