I have images in my local database which I want to populate in a listview.
This is what I'm doing :
...
bitmap[i] = MySQLiteHelper.getImage(images[i]);
// This fetches the bitmap image from database
...
Here, I'm converting my Bitmap to a Drawable.
d[i] = new BitmapDrawable(getResources(),bitmap[i]);
Then I'm using this Drawable in HashMap's put method to set it as a listView item.
hm.put("img", String.valueOf(d[i]));
// put() accepts java.lang.String as input.
But the image is not displayed in the listview. I'm able to display all the text, but not the image.
I'm getting the following error in my LogCat :
BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: android.graphics.drawable.BitmapDrawable@3ab28e36: open failed: ENOENT (No such file or directory)
resolveUri failed on bad bitmap uri: android.graphics.drawable.BitmapDrawable@3ab28e36
What am I doing wrong here? I think that when converting that Bitmap to Drawable, the drawable is holding a temporary value and the put() cannot access that? What is wrong here folks, any help please?
EDIT :
My HashMap code :
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<len;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("img", String.valueOf(d[i]));
hm.put("tit", " Title : " + title[i]);
hm.put("init", " Initial Price : " + init_price[i]);
hm.put("cur"," Current Price : " + cur_price[i]);
aList.add(hm);
}
// Keys used in Hashmap
String[] from = { "img","tit","init","cur" };
// Ids of views in listview_layout
int[] to = { R.id.img,R.id.tit,R.id.init,R.id.cur};
getImage() method :
The image (Bitmap) is stored in the database as BLOB. I obtained it as a ByteArray. Now, I'm converting it back to Bitmap using the below method.
// convert from byte array to bitmap
public static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
My Logcat : after using Base64
to convert Bitmap
to String