Reputation: 1437
Which field is suitable for the image. varchar or blob and why?
I'm using the following code to convert the image:
public String getStringFromBitmap(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 70, stream);
return Base64.encodeToString(stream.toByteArray(), Base64.NO_WRAP);
}
public Bitmap getBitmapFromString(String imageString) {
byte[] decodedString = Base64.decode(imageString, Base64.NO_WRAP);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,
decodedString.length);
return decodedByte;
}
my field is varchar. Is This The Way is better? Or do I have to change my way
Upvotes: 1
Views: 1321
Reputation: 152857
Neither one is good.
Image data tends to take a lot of space and the Android sqlite wrapper (CursorWindow
specifically) doesn't work very well when a lot of data is being pulled from the database.
Instead, store the binary data in the filesystem and just store a path in the database.
Upvotes: 4
Reputation: 1443
there is no varchar(exactly) in SQLite!!!(SQLite DataType)
NULL. The value is a NULL value.
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
BLOB. The value is a blob of data, stored exactly as it was input.
seem blob is better than other for image
Upvotes: 0