Displaying image from the sqlite database using cursor in android -
i want display image in imageview sqlite database using cursor. used below code retrieve image not able display image in imageview.
cursor c=this.db.query(table_name, new string[] { "name","price","image" }, null, null, null, null, null); name.settext(c.getstring(0)); price.settext(c.getstring(1)); byte b[]=c.getblob(2); bitmap bp=bitmapfactory.decodebytearray(b, 0, b.length); imageview image=(imageview)findviewbyid(r.id.imageview); //bytearrayinputstream imagestream = new bytearrayinputstream(b); //bitmap theimage = bitmapfactory.decodestream(imagestream); //image.setimagebitmap(theimage); image.setimagebitmap(bp); other image, name , price display image not display. suggestion or code me solve problem.
please me.
thanks in advance..
i've tried use stream instead of byte array, mine example works me. try use cursor.getcolumnindex()
byte[] blob = c.getblob(c.getcolumnindex(yourdb.image)); bytearrayinputstream inputstream = new bytearrayinputstream(blob); bitmap bitmap = bitmapfactory.decodestream(inputstream); here's "create table" statement, pls double check yours
create table datatable(_id integer primary key autoincrement, image blob, price integer);
Comments
Post a Comment