0

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)

rib
  • 190
  • 1
  • 11

3 Answers3

0

As your error points out, your image is too large to load.

Basically right now you are loading the whole image into memory.

You have to get a smaller /scaled down version of the bitmap.

You can easily do this using BitmapFactory.Options,

Here is a link which goes into detail on the recommended technique to use for this: developer.android.com/training/displaying-bitmaps/load-bitmap.html

AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56
  • But will I loose quality and why isn't it working on Android 6 but on Android 5? – rib Apr 26 '16 at 16:40
  • Image quality is not necessarily focused on the Android version but can also vary from phone to phone. Your app cannot even handle the the current bitmap, so quality should be the least of your concerns. I would advise running some tests using a different sample size. – AndroidEnthusiast Apr 26 '16 at 16:44
  • But without the "high" quality you won't see anything if you zoom in. – rib Apr 26 '16 at 16:46
  • I see the size above is even 3240x5760, way to big. – AndroidEnthusiast Apr 26 '16 at 16:46
  • I don't know the exact error px, but I saved the images as 1920/1080, so this can't be to big – rib Apr 26 '16 at 16:56
  • Try this approach, when the image is zoomed out you load image with lower quality, because user wouldn't see difference, but when user zoom in you would load only part of high quality image which is visible for user. – MyWay Apr 26 '16 at 17:02
  • @MyWay sounds ok, but it sounds, quite complicated, do you have some example code? – rib Apr 26 '16 at 18:01
0

Please check "Bitmap too large to be uploaded into a texture"

and Prevent bitmap too large to be uploaded into a texture android

It has the same error with your log

Community
  • 1
  • 1
Liem Vo
  • 5,149
  • 2
  • 18
  • 16
0

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

Atiq
  • 14,435
  • 6
  • 54
  • 69