Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another quicker WorkAround for the OutOfMemory Issues, is to try/catch the code where you decode the image and if the OutOfMemory-exception is thrown, you try to decode it with smaller Resolution again..</p> <p>something like this:</p> <pre><code>private static Bitmap decodeFile(File f, int size, int suggestedScale) { int scale = 1; Bitmap bmp = null; try { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f), null, o); // Find the correct scale value. It should be the power of 2. int width_tmp = o.outWidth, height_tmp = o.outHeight; if(suggestedScale &gt; 0) scale = suggestedScale; else { if (width_tmp &gt;= height_tmp) { scale = Math.round((float)(width_tmp) / size); } else { scale = Math.round((float)(height_tmp) / size); } } if(scale &lt; 2) return BitmapFactory.decodeFile(f.getPath()); Debug.i(TAG, "width: " + width_tmp + " height: " + height_tmp + " scale: " + scale); // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; bmp = BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) { } catch(OutOfMemoryError e) { Debug.i(TAG, "we retry it cause of an OutOfMemoryException"); return decodeFile(f, size, scale+1); } catch(Exception e){ Debug.w(TAG, e); } return bmp; } </code></pre> <p>Ofcourse it is now possible, that you will see different resolutions of the same picture at different times - But at least your Gallery will not crash anymore and you allways show the highest resolution you can.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload