问题
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\">
回答1:
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:
- 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. - create scaled images on all densities
mdpi
,hdpi
,xhdpi
,xxhdpi
to avoid runtime over-scaling and to have smaller images on older devices.
来源:https://stackoverflow.com/questions/28346407/bitmap-too-large-to-be-uploaded-into-a-texture