in the database helper class DBAdaper ie declares the table as follows
private static final String USERDETAILS= "create table userdetails(usersno integer primary key autoincrement,userid text not null ,username text not null,password text not null,photo BLOB,visibility text not null);";
insert values ββlike this
first convert images as bytes []
ByteArrayOutputStream baos = new ByteArrayOutputStream(); Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.common)).getBitmap(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] photo = baos.toByteArray(); db.insertUserDetails(value1,value2, value3, photo,value2);
in class DEADaper
public long insertUserDetails(String uname,String userid, String pass, byte[] photo,String visibility) { ContentValues initialValues = new ContentValues(); initialValues.put("username", uname); initialValues.put("userid",userid); initialValues.put("password", pass); initialValues.put("photo",photo); initialValues.put("visibility",visibility); return db.insert("userdetails", null, initialValues); }
get the image as follows
Cursor cur=your query; while(cur.moveToNext()) { byte[] photo=cur.getBlob(index of blob cloumn); }
convert byte [] to image
ByteArrayInputStream imageStream = new ByteArrayInputStream(photo); Bitmap theImage= BitmapFactory.decodeStream(imageStream);
I think this content may solve your problem.
Balaji.K Sep 07 '11 at 9:50 a.m. 2011-09-07 09:50
source share