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.
}
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With