我想知道是否有办法的类型(.gif注意)图像保存到sqllite数据库。如果是的话应该怎么我的 DatabaseAdapter
的样子。
I'd like to know if there's a way to save Images (of the type .gif) to the sqllite-database. If yes how should my DatabaseAdapter
look like.
也有性能问题?
您应该使用 BLOB
在数据库:
阅读本教程...
http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html
但一想到我告诉你降负荷和存储图像的地图,这是适合你简单。
but one think i tell you down load and store image in map this is suits you simple.
code:
Stroring -
Map<String, byte[]> hh = new HashMap<String, byte[]>();
String hi = "https://m.xsw88.com/allimgs/daicuo/20230912/4724.png.jpg";
byte[] logoImagedata = getLogoImage(hi);
hh.put("img",logoImagedata);
retriving -
byte[] imageByteArray = hh.get("img");
ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray);
Bitmap theImage= BitmapFactory.decodeStream(imageStream);
getLogoImage() -
private byte[] getLogoImage(String url){
try {
URL imageUrl = new URL(url);
URLConnection ucon = imageUrl.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return baf.toByteArray();
} catch (Exception e) {
Log.d("ImageManager", "Error: " + e.toString());
return null;
}
}
这会帮助你。