2

I have a 1080x1920px image that I want to use as background image in my app.

On my Galaxy S6 it works fine, but as I go down to a smaller screen size (S4 i.e) I receive this:

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

in addition of the image not being displayed at all.

This is my layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}"
android:background="@drawable/bg">

<EditText android:id="@+id/username_textfield"
          android:layout_width="270dp"
          android:layout_height="40dp"
          android:hint="Username"
          android:textColorHint="#ffffff"
          android:textColor="#ffffff"
          android:ellipsize="start"
          android:gravity="center_horizontal"
          android:singleLine="true"
          android:layout_marginTop="50dp"
          android:layout_marginLeft="60dp"
          android:background="@drawable/textfield_bg"/>

<EditText android:id="@+id/password_textfield"
          android:layout_width="270dp"
          android:layout_height="40dp"
          android:hint="Password"
          android:textColorHint="#ffffff"
          android:textColor="#ffffff"
          android:ellipsize="start"
          android:gravity="center_horizontal"
          android:singleLine="true"
          android:layout_marginTop="10dp"
          android:layout_marginLeft="60dp"
          android:background="@drawable/textfield_bg"/>

And my MainActivity is empty except for the onCreate. I have read the other posts about this issue, but none has provided any real solution for me.

HassanUsman
  • 1,787
  • 1
  • 20
  • 38
Knut
  • 107
  • 9
  • Possible duplicate of ["Bitmap too large to be uploaded into a texture"](http://stackoverflow.com/questions/10271020/bitmap-too-large-to-be-uploaded-into-a-texture) – Shark Mar 21 '16 at 14:01
  • See RomainGuy's [answer here](http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit) – Shark Mar 21 '16 at 14:02
  • 1
    The image is scaled based on the pixel density of your device. The image is in fact too large. You can determine the max size OpenGL will allow and resize your bitmap to fit if you want it to work for all bitmaps, including those dynamically added. Regarding the link @Shark made to Romain's answer you will probably want to look at this as well: http://stackoverflow.com/questions/26985858/gles10-glgetintegerv-returns-0-in-lollipop-only/27092070#comment59878380_27092070 – zgc7009 Mar 21 '16 at 14:07
  • You have image in wrong folder use drawable-nodpi instead of drawable http://stackoverflow.com/q/36113734/4267244 – Dalija Prasnikar Mar 21 '16 at 14:08
  • @DalijaPrasnikar That actually got it working! – Knut Mar 21 '16 at 15:22
  • Understand that the drawback of that is that Android won't perform any scaling on the image. If that works for you in this case, perfect, but think about it – zgc7009 Mar 21 '16 at 20:35

2 Answers2

3

You should create drawable folder name nodpi. The nodpi apks work with all phones .

A drawable in res/drawable-nodpi/ is valid for any screen density .if there is another drawable with the same base name in a density-specific directory, and the device running your app happens to have that screen density, the density-specific resource will be used. As a result, -nodpi becomes a fallback, to be used in cases where you do not have something specific for a density.

Read CommonsBlog

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

If you're using Android Studio you may try to add bg as image or vector asset

Canberk Ozcelik
  • 631
  • 1
  • 11
  • 26