M
M
M E2015-03-10 21:56:20
Android
M E, 2015-03-10 21:56:20

How to store images in sqlite android?

You need the ability to attach pictures to notes (1 or more).
Notes are stored in the database in String.
And how to organize the storage of images?
Use an array of strings in which to store the addresses of the pictures?
Where are the pictures stored? In the application folder on the phone or on the flash drive?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Oleg Gamega, 2015-03-12
@gadfi

for those who store pictures in the database there is a separate frying pan !!! Cases when this may be necessary can be read on the fingers.
Store paths in the database.

O
one pavel, 2015-03-10
@onepavel

Storing a list of paths, names, or their hashes in a database is common practice.
It is possible to store on a flash drive, no - in the internal memory.

E
Emil Valiyev, 2015-03-11
@skykoder

in Base64 format you can save in database. Here is an example:

//конвертируем Bitmap на Base64 
public String convertToBase64(Bitmap bitmap) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG,100,os);
        byte[] byteArray = os.toByteArray();
        return Base64.encodeToString(byteArray, 0);
    }

//и наоборот
public Bitmap convertToBitmap(String base64String) {
        byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
        Bitmap bitmapResult = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        return bitmapResult;
    }

C
constv, 2015-03-11
@constv

SQLiteStatement.bindBlob Cursor.getBlob

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question