Skip to content Skip to sidebar Skip to footer

App Crashing After Selecting Photo From Gallery

I created an image processing app which shows percentage of similarity between images using openCV. However, whenever I select an image the application process crashes. Here is the

Solution 1:

Your file is too big. Add try-catch block and try to load smaller images with options.inSampleSize (try different values for options.inSampleSize)

Example:

Bitmapbitmap=null;

try{
bitmap =  BitmapFactory.decodeResource(getResources(), R.drawable.cleaf5, options);
}catch(OutOfMemoryError e)    
   try{
   BitmapFactory.Optionsoptions=newBitmapFactory.Options();
   options.inSampleSize = 8;
   bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cleaf5, options);
   }catch(OutOfMemoryError e) {}
}

if(bitmap != null){
//do smth
}

Post a Comment for "App Crashing After Selecting Photo From Gallery"