Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

android - Bitmap too large to be uploaded into a texture

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">
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...