我只是想知道,我該如何將字節數組轉換爲blob?如何將字節數組轉換爲Android中的Blob數據類型
我的數據庫看起來是這樣的:
Photo
id (int) | image_key (blob)
這是我的代碼:
//this for getting data from picture
Bitmap yourImage = extras.getParcelable("data");
// convert bitmap to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
//the problem is right here, i want to convert this byte array, to a blob data type
byte imageInByte[] = stream.toByteArray();
我如何轉換這個字節數組到我的數據庫的照片,並把它放在現場image_key(BLOB) ?因爲我嘗試過但有錯誤。有人能幫我解決這個錯誤嗎?請我需要幫助..
我錯誤?看起來像這可能是重複的副本:http://stackoverflow.com/questions/4191136/how-to-store-and-retrieve-a-byte-array-image-data-to-and-from-a -sqlite-databas – IrishGeek82
@ IrishGeek82好吧,錯誤看起來像我不能把imageInByte [B @ 421a0a0的值放到blob數據類型中,所以查詢是INSERT INTO Photo(image_key)VALUES('[B @ 421a0a0' ),請糾正我,如果我錯了。 – user3747208
您是否在使用類似的東西? cv.put(CHUNK,buffer); // table CHUNK blob type字段 long rawId = database.insert(TABLE,null,cv); // TABLE table name – IrishGeek82