Bitmap too large to be uploaded into a texture
Asked Answered
E

1

12

I've in drawable directory an image file with the 960x1440 size. When the app start, the image is not loaded as background and in the logcat I see:

Bitmap too large to be uploaded into a texture (2880x4320, max=4096x4096)

Why it says 2880x4320 if the image is 960x1440 ?

The bitmap is loaded via xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/launcher_bg"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">
Erdmann answered 5/2, 2015 at 14:22 Comment(5)
Please provide some example code, where you load the texture.Ineludible
did you checked all your drawable folders if there isn't a to big file in them? Your app is working without the background image? What kind of image file is that, png, jpg?Ineludible
I've only 1 file for all resolution (in drawable) of 1.02 mb and with 960x1440 size... yes, the app runs without the bg image... but not on all devices, only on Nexus 5 at the momentErdmann
I don't believe this, sorry ;) Espacilly you saying that it only runs on an nexus 5, I think your other test device are older right? The message says something about texture which indicates opengl engine of the soc, which has different limits on different devices and socs.Ineludible
only on Nexus 5 it doesn't load the image...Erdmann
L
49

an image in the /drawable/ folder without any specification is considered to be the "default", that is for 1dp = 1px that is mpdi, then because the device you're actually running is xxhdpi that image get's scaled up during runtime.

The original image might be 960x1440, but the conversion from mdpi to xxhdpi is 3 times the size, so your 960x1440 becomes (3*960)x(3*1440) = 2880x4320, which is too large of a texture to apply to the hardware accelerated views.

so to fix that is actually pretty simple, you have two choices:

  1. move your image to /drawable-nodpi/ that's simple, reduces the .apk size, but lower end devices might struggle to load such a big image.
  2. create scaled images on all densities mdpi, hdpi, xhdpi, xxhdpi to avoid runtime over-scaling and to have smaller images on older devices.
Longdrawn answered 5/2, 2015 at 15:51 Comment(1)
actually no 2. is now pretty simple, thanks to Android Drawable Importer pluginDeathwatch

© 2022 - 2024 — McMap. All rights reserved.