androidandroid-5.0-lollipopandroid-6.0-marshmallowopenglrenderer

Load huge image from file


I'm using pictures which are stored on the Environment.getDataDirectory() and they are 1920 width and 1080 high and I want to load them in a Image View with this code:

File imgFile = new File(Environment.getDataDirectory() + "/data/com.My.Package/files/Pictures/Sun.jpg");                
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                zoomImage.setImageBitmap(myBitmap);

But on Android 6.0 (Samsung Galaxy S6 Edge) I'm getting this error, on Android 5 (HTC One) it's working pretty well:

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (3240x5760, max=4096x4096)

So now to the Question: Is there a way to avoid this error and without a quality drop (I will need this quality, because you can zoom the Image)


Solution

  • I think you should try loading it with Glide.

    The procedure is pretty straight forward and its fast and there won't be any OOM hopefully

    Just compile this in your build.gradle

     compile 'com.github.bumptech.glide:glide:3.7.0'
    

    and then

    Glide
        .with(this)
        .load(imgFile)
        .into(zoomImage);
    

    and that's it, you will never face OOM again hopefully, I worked with images in my many apps and I have never faced OOM with it.

    Hope it helps