which data type should I use for storing an image in sqlLite database table??
the following is my attempt:
@Override
public void onCreate(SQLiteDatab
Try this..
Creating a table with a BLOB column:
CREATE TABLE storedImages (_id INTEGER PRIMARY KEY, myImage BLOB);
Downloading an image using HTTP and storing it in your table:
DefaultHttpClient mHttpClient = new DefaultHttpClient();
HttpGet mHttpGet = new HttpGet("your image url");
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = mHttpResponse.getEntity();
if (entity != null) {
// insert to database
ContentValues values = new ContentValues();
values.put(MyBaseColumn.MyTable.ImageField, EntityUtils.toByteArray(entity));
getContentResolver().insert(MyBaseColumn.MyTable.CONTENT_URI, values);
}
}
Loading the BLOB into an ImageView:
ImageView myImage = (ImageView) findViewById(R.id.myImage);
byte[] bb = cursor.getBlob(cursor.getColumnIndex(MyBaseColumn.MyTable.ImageField));
myImage.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
Refer to the SQLite documentation on datatypes.
You probably want a BLOB
type, also known as "binary blob" or "Binary Long OBject". Just be aware that storing really big things in an SQLite database isn't necessarily a good idea - images are usually better off stored in the filesystem if you can manage it.
Saving Images in to Sqlite is bad idea. You should save its path in to sqlite. Images are big in size comparing to textual information.
It would be hard for saving and retrieving images from sqlite.
So, I would like suggest you to store images in external folder and store its path in to sqlite database.