views:

479

answers:

2

Hi folks,

I've written an app, thats loading images either using the android gallery app or by taking a photo using the cam.

When I now load an image using the gallery, everything is fine. When the code is being executed a second time (for loading another image), the application crashes.

            try {
            Uri data = intent.getData();
            ContentResolver cr = this.getContentResolver();
            Bitmap mBitmap = null;
            mBitmap = Media.getBitmap(cr, data);
            imageView.setImageBitmap(mBitmap);
        } catch(Exception e){
            showToast(this, "Failed loading image from gallery");
            return;
        }

The code crashes at the line mBimap = Media.getBitmap(cr, data);. Everything is initialized, there are no null values etc. The strange thing is: no exception is thrown, I don't get into the catch block to determine whats going wrong.

Does anyone have an idea about this? Am I not allowed to "re-use" the content resolver? Do I have to free it after the first usage or something like this?

A: 

Thanks a lot! The look at the logs definately told me, that I was allocating too much space at one time.

After a lot trial&error I finally found out how to load thumbs from the gallery and fixed the issue that way. Thanks a lot for your answers!

Hi, could you elaborate please?
Pandalover
A: 

Just for the record, can you share us your solution?

Did you use sampleSize?

BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 10;
Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,options);
hcpl