2011-04-07 138 views

回答

1

是的,你可以從SD卡獲取圖像並將其存儲在SQLite數據庫,我們已經做到了,但它會爲你的設備太昂貴了.......所以,要小心即,

呼叫通過調用圖像拾取這個意圖

Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); 
        startActivityForResult(i, 12); 

它會打開默認的畫廊選擇器視圖,當你選擇,你會在你當前活動返回的圖像,所以覆蓋onActivityResult()並查找結果代碼12.

在該代碼

您可以通過這些線路

Cursor cursor = getContentResolver().query(selectedImage, 
        filePathColumn, null, null, null); 
cursor.moveToFirst(); 

從這個光標對象獲取光標,你可以通過這些線路

int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
String filePath = cursor.getString(columnIndex); 

這裏獲取圖像的文件路徑爲位圖對象

Bitmap bMap = BitmapFactory.decodeFile(filePath); 

Get byte arrays

ByteArrayOutputStream out = new ByteArrayOutputStream(); 

bMap.compress(Bitmap.CompressFormat.PNG, 100,out); 
byte[] imageArray = out.toByteArray(); 

現在,您必須將imageArray作爲blob存儲在數據庫中。你完成了....不要忘記從我從哪裏得到的解決方案this post ...

+0

其實我需要在我的應用程序中這樣做的代碼? – info 2011-04-07 06:06:18

+0

檢查我編輯的答案..... – Prasham 2011-04-07 06:27:54

+0

感謝您的詳細發佈! – info 2011-04-07 08:20:53

相關問題