4

I'm currently developing a new app for the company I'm working at. We test this on multiple devices, now a strange thing I noticed the other day, well someone else did.

My Colleague tested the app on his HTC one m8, and we have a background image on the login page but it didn't show for him. It did however on a Nexus 7, Samsung Galaxy Tab 4, Motorola G and Samsung S4.

This might be very specific, but I guess some people must have noticed this kind of behaviour before on certain devices and found out why this could possibly occur?

The image is saved in the regular drawable folder and has a size of 1400px933px and it's a jpeg.

I wonder if anyone has any clue.

The ImageView is the first child of a relative layout, with a size of match parent in both width and Height. So it should just fit, other views are on top of this one.

Mathijs Segers
  • 6,168
  • 9
  • 51
  • 75

3 Answers3

4

I believe this problem is also to do with how android scales the images. Try putting the image into a drawable-nodpi resource folder.

The drawable folder is the same as drawable-mdpi. On the HTC One M8 images qualified as mdpi are scaled up by a factor of 3. So your 1400x933px image becomes 4200x2799px. The maximum size allowed by OpenGL is 4096x4096.

Breavyn
  • 2,232
  • 16
  • 29
2

I faced a similar issue with Samsung Galaxy Note 3. This was the only device that failed to load a large bitmap image. After a quite long search I finally found that some phone uses a small heap size for applications by default. This is because of the memory optimization and preventing memory leak issue. So basically you can do the following things to solve this,

  1. Use android:largeHeap="true" on the element in the activity manifest. This will give your application a large heap size.

  2. Use a Image Loading library like Android-Universal-Image-Loader

  3. Use an optimized image with less resolution.

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • Yep you will find the debugger will tell you `W/OpenGLRenderer﹕ Bitmap too large to be uploaded into a texture` – Breavyn Jun 08 '15 at 07:46
  • Exactly! @Colin Gillespie. This is weird but happens in some devices. – Prokash Sarkar Jun 08 '15 at 07:48
  • Ok I'm aware of the too big for device issue. I'll check if it's this but you'd expect one of the High end devices to be able to work with "large" bitmaps . Whilst it's not even big. But I'll check – Mathijs Segers Jun 08 '15 at 07:51
  • I will but I do prefer colin's approach if that works. The LargeHeap I've used in the past but it just makes it possible to let the Heap grow, not something I really want :) and when you implement it, do check the memory usage of your app, it might have leaks and grow to insane memory usage. – Mathijs Segers Jun 08 '15 at 08:37
  • I Didn't try all of it since the image is already low quality and such, Colin's issue resolved it, I should have used a nodpi folder instead of without suffix. – Mathijs Segers Jun 09 '15 at 06:50
1

This may be answered but because my search led me here, and it probably will for others. My xml looked like this before. Was surprised to see it generated app:srcCompat cause I never heard of that. I kept the code as is and copied "@drawable/your_image" as a value for a new attribute I added android:src.

<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:srcCompat="@drawable/salwa_small"
  android:id="@+id/img_my_profile_picture"/>

After:

<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:srcCompat="@drawable/salwa_small"
  android:src="@drawable/salwa_small"
  android:id="@+id/img_my_profile_picture"/>

I was only able to see the picture in the android studio designer prior but after it appears in both.

Omar Abdel Bari
  • 934
  • 9
  • 17