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. 通过sqlite数据库中的URL在iOS Web视图中显示图像
- 2. 在DataGridViewImageColumn中显示图像从Sqlite数据库中的[Winform]
- 3. 在android中显示来自sqlite数据库的图像?
- 4. 在SQLite数据库的ListView中显示图像
- 5. 在uiimageview中显示来自sqlite数据库的图像
- 6. 数据库中的图像url不在php中显示
- 7. 如何使用sqlite数据库中的JasperReports显示blob对象图像?
- 8. 从SQL Server数据库获取图像url以显示图像
- 9. 显示数据库中的图像
- 10. 从sqlite数据库中获取图像并使用JavaScript在页面上显示
- 11. 从vb.net的数据库中的数据库中显示图像
- 12. 显示SQLite数据库
- 13. 使用PHP显示存储在SQL数据库中的URL图像
- 14. 显示从数据库中的图像,图片不显示使用php
- 15. 从数据库中显示图像
- 16. 从数据库中显示图像
- 17. 在Javascript中显示数据库图像
- 18. 在数据库中显示图像
- 19. 显示图像从数据库中ASP.NET
- 20. 从android数据库中显示图像
- 21. 从数据库中显示图像
- 22. 从数据库中显示图像
- 23. 从数据库中显示图像php
- 24. 从数据库中显示图像
- 25. PHP从数据库中显示图像
- 26. 如何在html页面中使用数据url显示图像
- 27. 如何显示从SQLite数据库(retrive)图像
- 28. 无法使用PHP显示数据库中的斑点图像
- 29. 使用php显示存储在数据库中的图像(tinyblob)
- 30. 不能使用cakephp显示数据库中的图像
这里是[教程](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 -数据库/) –