MAIN
please help me am try to store image as blob in sqlite but i got like string format i don't know what i am doing wrong..
public byte[] photo=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button insert=(Button)findViewById(R.id.insert);
final SQLiteDatabase db;
db=openOrCreateDatabase("demo", Context.MODE_PRIVATE, null);
db.execSQL("create table if not exists demo1(Dp BLOB );");
insert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bitmap b=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//ContentValues cv=new ContentValues();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 90, bos);
photo=bos.toByteArray();
db.execSQL("INSERT INTO demo1(Dp)VALUES('"+photo+"')");
}
});
}
Aucun commentaire:
Enregistrer un commentaire