【问题标题】:Bitmap too large位图太大
【发布时间】:2016-03-21 13:59:13
【问题描述】:

我有一张1080x1920px 图像,我想在我的应用中用作背景图像。

在我的Galaxy S6 it 上工作正常,但是当我减小到较小的屏幕尺寸(S4 即)时,我收到了这个:

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

除了根本不显示的图像。

这是我的布局:

<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"/>

我的 MainActivity 是空的,除了 onCreate。 我已阅读有关此问题的其他帖子,但没有一个为我提供任何真正的解决方案。

【问题讨论】:

标签: android bitmap


【解决方案1】:

您应该创建名称为 nodpi 的可绘制文件夹。 nodpi apk 适用于所有手机。

res/drawable-nodpi/ 中的可绘制对象适用于任何屏幕密度。如果 在 a 中有另一个具有相同基本名称的可绘制对象 特定于密度的目录,而运行您的应用程序的设备恰好 具有该屏幕密度,将使用特定于密度的资源。 结果, -nodpi 成为一个后备,用于您 没有特定于密度的东西。

阅读CommonsBlog

【讨论】:

    【解决方案2】:

    如果您使用的是 Android Studio,您可以尝试将 bg 添加为图像或矢量资源

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      • 2011-09-01
      • 2021-03-08
      • 2014-02-14
      • 2020-03-22
      相关资源
      最近更新 更多