Android OutOfMemoryError for large images

后端 未结 3 1380
迷失自我
迷失自我 2021-01-25 05:39

The method throws OutOfMemoryError for large images in size( not by resolution) i have 12 MP photos, all of them are different in size(1.5MB, 2.5MB, 3.2MB, 4.1MB) etc and the re

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 05:51

    Please try with these Option properties..

        BitmapFactory.Options opts=new BitmapFactory.Options();
        opts.inDither=false;                     //Disable Dithering mode
        opts.inPurgeable=true;                   //Tell to gc that whether it needs free memory, the Bitmap can be cleared
        opts.inInputShareable=true;              //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
        opts.inTempStorage=new byte[32 * 1024];
        opts.inSampleSize = 1;
    

    To reduce the quality of image file increase the number of opts.inSampleSize. Click here for more details

    And add one more attribute in Manifest.xml in application tag

    android:largeHeap="true"

提交回复
热议问题