2015-01-21 51 views
-3

我想創建一個學習應用程序.IT包含一個圖像和四個可能的答案,其中之一是真實的...我創建了3個表格 圖像表,包含主要關鍵字 與字標識和簇號我如何使用android中的圖像填充圖像數據庫?

現在我怎麼能填充圖像表從系統圖像和圖像視圖訪問圖像這個詞 簇表的字ID和複雜性的複雜表

public class Database extends SQLiteOpenHelper 
{ 
    private static final int DATABASE_VERSION = 2; 
private static final String DATABASE_NAME = "kid.db"; 

public Database(Context context) 
{ 
    super(context,DATABASE_NAME,null,DATABASE_VERSION); 
} 

@Override 
public void onCreate(SQLiteDatabase sqLiteDatabase) 
{ 
    final String SQL_CREATE_IMAGE_TABLE = "create table image(word_ID integer primary key,word text not null,img blob);"; 

    final String SQL_CREATE_COMPLEXITY_TABLE = "create table compexity(WORD_ID integer primary key,complexity integer not null);"; 

    final String SQL_CREATE_CLUSTER_TABLE = "create table cluster(WORD_ID integer primary key,cluster integer not null);"; 

    sqLiteDatabase.execSQL(SQL_CREATE_IMAGE_TABLE); 
    sqLiteDatabase.execSQL(SQL_CREATE_COMPLEXITY_TABLE); 
    sqLiteDatabase.execSQL(SQL_CREATE_CLUSTER_TABLE); 

} 

@Override 
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) 
{ 


} 

}

+0

[http://www.androidhub4you.com/2012/09/hello-friends-today-i-am-going-to-share.html ](http://www.androidhub4you.com/2012/09/hello-friends-today-i-am-going-to-share.html) – 2015-01-21 06:56:51

回答

1
Cursor c = db.query(your query statment); 
if(c != null && c.getCount()!=0){ 
byte[] blob = c.getBlob(c.getColumnIndex(YourDB.ColumnName)); 
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob); 
Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 
} 

將此位圖設置爲您的ImageView。 也檢查你的圖像列必須是BLOB類型。

+0

如果你可以分享整個代碼......這將有助於.. – 2015-01-21 07:00:15

0

您可以在表格中的圖像列中放置一個字節[]。

例如:要添加行到您的IMAGE_TABLE

public void addEntry(String word, byte[] image) throws SQLiteException{ 
ContentValues cv = new ContentValues(); 
cv.put(KEY_NAME, word); 
cv.put(KEY_IMAGE, image); 
database.insert(DB_TABLE, null, cv);