AndroidのSQLiteデータベースとの間でバイト配列(画像データ)を保存および取得するにはどうすればよいですか?
21752 次
1 に答える
12
バイト配列は BLOB データ型として格納できます。この手順には、次のようなチャンクに対する特別な注意を除いて、特別なことは何もありません。
InputStream is = context.getResources().open(R.drawable.MyImageFile);
try {
byte[] buffer = new byte[CHUNK_SIZE];
int size = CHUNK_SIZE;
while(size == CHUNK_SIZE) {
size = is.read(buffer); //read chunks from file
if (size == -1) break;
ContentValues cv = new ContentValues();
cv.put(CHUNK, buffer); //CHUNK blob type field of your table
long rawId = database.insert(TABLE, null, cv); //TABLE table name
}
} catch (Exception e) {
Log.e(TAG, "Error saving raw image to: "+rawId, e);
}
于 2010-11-22T15:05:56.887 に答える