如何使用ByteArrayInputStream从SQLite中检索图像

时间:2012-07-26 12:13:51

标签: android sqlite bytearrayinputstream

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

1 个答案:

答案 0 :(得分: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方法设置图像