3

in my application i have a database where i store image .i want to retrieve images.images are easly retrieve in BitMap but the problem is how can i convert that BitMap image into integer format.

this is code:

   DataBaseClass objOfDataBaseClass=new DataBaseClass(context);
    Cursor mCursor=objOfDataBaseClass.showData();//here is all data taken from dataBase

if(mCursor.moveToNext()) {

        byte[] mg=null;
        mg = mCursor.getBlob(mCursor.getColumnIndex("image"));
        Bitmap bitmap = BitmapFactory.decodeByteArray(mg, 0, mg.length);

         int[] store=?//how can i bitMap store in this array.
}

2 Answers 2

1

You can use the Bitmap.getPixels method (documentation)

int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] store = new int[width * height];
bitmap.getPixels(store, 0, width, 0, 0, width, height);
Sign up to request clarification or add additional context in comments.

Comments

1

You shouldn't store the pixels of the bitmap itself, as a bitmap contains the image in uncompressed form and that would result in a huge amount of data (e.g. 1024 x 768 x 32 bit is 3.1 MB).

Better compress the bitmap to e.g. an PNG and store that in the database. You can use Bitmap.compress() for that purpose and use a ByteArrayOutputStream to write the data to. Then, store the bytes of that outputstream to your database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.