0
A
回答
0
試試這個代碼。
URL url = new URL("your image url");
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is,128);
ByteArrayBuffer barb= new ByteArrayBuffer(128);
//read the bytes one by one and append it into the ByteArrayBuffer barb
int current = 0;
while ((current = bis.read()) != -1) {
barb.append((byte) current);
}
ContentValues filedata= new ContentValues();
//TABLE_FIELD = a field in the database table of type text
filedata.put(TABLE_FIELD,barb.toByteArray());
//TABLE_NAME = a table in the database with a field TABLE_FIELD
db.insert(TABLE_NAME, null, filedata);
//Retriving Data from DB:
//select the data
Cursor cursor = db.query(TABLE_STATIONLIST, new String[] {TABLE_FIELD},null, null, null, null, null);
//get it as a ByteArray
//reading as Binary large object(BLOB)
byte[] imageByteArray=cursor.getBlob(1);
//the cursor is not needed anymore so release it
cursor.close();
Bitmap image=getbyteAsBitmap(imageByteArray);
//use this method to convert byte[] to bitmap
private Bitmap getbyteAsBitmap(byte[] bytedata){
if(bytedata!=null){
ByteArrayInputStream imageStream = new ByteArrayInputStream(bytedata);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
//theImage=MediaProcesser.getRoundedCornerBitmap(theImage, 5);
return theImage;
}else{
return null;
}
}
相關問題
- 1. 在DataGridViewImageColumn中顯示圖像從Sqlite數據庫中的[Winform]
- 2. 如何使用sqlite數據庫中的JasperReports顯示blob對象圖像?
- 3. 顯示從數據庫中的圖像,圖片不顯示使用php
- 4. 如何在html頁面中使用數據url顯示圖像
- 5. 從android數據庫中顯示圖像
- 6. 在Javascript中顯示數據庫圖像
- 7. 從數據庫中顯示圖像php
- 8. 從數據庫中顯示圖像
- 9. 顯示圖像從數據庫中ASP.NET
- 10. 從數據庫中顯示圖像
- 11. 無法使用PHP顯示數據庫中的斑點圖像
- 12. 不能使用cakephp顯示數據庫中的圖像
- 13. 檢索Mysql數據庫中的圖像,並使用java顯示
- 14. 在sqlite數據庫的列表視圖中顯示標誌圖像
- 15. 如何使用MYSQLi查詢在數據庫中顯示圖像中的圖像?
- 16. 在SQLite數據庫中保存圖像
- 17. 在sqlite數據庫中添加圖像
- 18. 如何使用HTML + JS從數據庫中顯示圖像?
- 19. 使用文件目錄從數據庫中顯示圖像
- 20. 顯示圖像從數據庫在html中使用php
- 21. 如何在刺激中顯示沒有url數據庫圖像數據集
- 22. 無法顯示圖像從數據庫使用視圖模型
- 23. 如何顯示android sqlite中blob數據的圖像?
- 24. 將SQLite數據庫中的數據顯示在Android的ListView中
- 25. 更新的SQLite數據庫的圖像
- 26. 顯示SQLite數據庫內容的Android
- 27. 顯示從數據庫SQLite的
- 28. 如何顯示位圖上的圖像取自sqlite數據庫android
- 29. mysqli不顯示圖像數據庫
- 30. MVC數據庫圖像顯示彈簧
這裏是[教程](http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html) –
非常感謝先生。我仍然懷疑。就像我有一個gridview和圖像。所以當我點擊圖像時,我需要在edittext框中顯示該圖像。同樣,當我提交我需要在edittext上方的列表視圖中顯示該圖像。在這個問題上的任何幫助。 – user950203
可能的重複:[如何將URL從retiteived存儲在SQLite數據庫?](http://stackoverflow.com/questions/6815355/how-to-store-image-retreived-from-url-in-a-sqlite -數據庫/) –