Bilder als Blobs in SQLiteDatabase gespeichert sind.
Für ein Bild, um Datenbank Speicher
ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getItemname());
values.put(KEY_DESCRIPTION, contact.getDescription());
Log.i("","Adding image of Type Bitmap"+contact.getImage());
if(contact.getImage()!=null) {
values.put(KEY_IMAGE, Utility.getBytes(contact.getImage()));
}
Wo getBytes (Bitmap) wäre:
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
während ein Bild aus der Datenbank holen:
if(cursor.getBlob(3)!=null)
{
contact.setImage(Utility.getPhoto(cursor.getBlob(3));
}
else
{
contact.setImage(null);
}
Und getPhoto (BLOB) wäre:
// convert from byte array to bitmap
public static Bitmap getPhoto(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
Hallo Mohamed, Sie müssen Blobs verwenden. Siehe Antwort unter http://stackoverflow.com/questions/11790104/how-to-storebitmap-image-and-retrieve-image-from-sqlite-database-in-android http://stackoverflow.com/questions/9357668/how-to-speichern-image-in-sqlite-Datenbank –