user
user

Reputation: 471

How to fetch images from gallery and move in android application

I am working on Android Security app and I have to lock the images from gallery so I am trying to move images from gallery into my application.

I am using this code:

Cursor cursor = cursor1[0];
        int i = 0;
        while (cursor.moveToNext()) {

            String id = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID));
            long idC = Long.parseLong(id);
            Uri newUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, idC);
        try {
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(cr,newUri);
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100,stream );

                Bitmap compBit = Bitmap.createScaledBitmap(bitmap, 100,100, true);
                bitmap1[i] = compBit;
                bitmap.recycle();

            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

but getting this exception:

Out of memory on a 4192360-byte allocation.

Upvotes: 1

Views: 422

Answers (1)

Karan Nagpal
Karan Nagpal

Reputation: 541

there is a training module on Displaying Bitmaps Efficiently - [link] http://developer.android.com/training/displaying-bitmaps/index.html .

It provide good information on handling out of memory exception with sample.

Upvotes: 3

Related Questions