【问题标题】:Cannot generate texture from bitmap in Android无法在 Android 中从位图生成纹理
【发布时间】:2013-03-01 20:28:54
【问题描述】:

我目前正在开发一个 android 应用程序,直到现在我使用 eclipse android 模拟器来测试它。

今天我决定在我的手机(小米 mi2)上试一试,但是当我吃午饭时(通过 USB 调试)我遇到了 2 个问题:

  1. 我有一张模拟器可以完美显示的背景图片,但它没有出现在我的手机上 - 显示的是黑色背景。

  2. 这可能是上一个的问题,LogCat 显示一些错误:

03-01 22:18:35.599: E/OpenGLRenderer(1109): Cannot generate texture from bitmap 03-01 22:18:35.629: E/SpannableStringBuilder(1109): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

活动代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="480dip"
android:layout_marginTop="10dip"
android:background="@drawable/bg">
<EditText
    android:id="@+id/eu_un"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:hint="@string/enter_user_name" >
</EditText>

<EditText
    android:id="@+id/eu_pw"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/eu_un"
    android:ems="10"
    android:hint="@string/enter_password"
    android:inputType="textPassword|textPersonName" />

<Button
    android:id="@+id/nu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="134dp"
    android:text="@string/signup" />

<Button
    android:id="@+id/eu_signin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/eu_pw"
    android:layout_centerHorizontal="true"
    android:text="@string/login" />

<Button
    android:id="@+id/exit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/eu_signin"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="61dp"
    android:text="@string/exit" />

</RelativeLayout>

Java 代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    un = (EditText) findViewById(R.id.eu_un);
    pw = (EditText) findViewById(R.id.eu_pw);
    nu = (Button) findViewById(R.id.nu);
    eu = (Button) findViewById(R.id.eu_signin);
    exit = (Button) findViewById(R.id.exit);
    ma = this;

    nu.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            newUser();
        }
    });

【问题讨论】:

  • 当图像的位图由于回收而丢失时会发生这种情况,或者在硬件加速(和 openGLRenderer)的情况下,当打开的 GL 上下文丢失时会发生这种情况。你的代码是什么样的?
  • 图片的代码?
  • Activity 中的代码。
  • 查看编辑后的帖子。谢谢
  • 你还有.java文件吗?

标签: android bitmap


【解决方案1】:

这是一个奇怪的错误。我做了一些搜索,发现一些类似的帖子似乎表明它与设备的键盘设置有关:

Android - SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Nexus 7 error "SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length"

他们中的大多数人在问题中都有特定的电话。

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length error whenever an editText becomes empty

如果你搜索的话,还有很多

http://www.google.com/search?client=safari&rls=en&q=SPAN_EXCLUSIVE_EXCLUSIVE+spans+cannot+have+a+zero+length&ie=UTF-8&oe=UTF-8

我知道这并不能完全提供您所希望的答案 - 但理想情况下它会让您朝着正确的方向前进。

【讨论】:

  • 谢谢,spans 错误与我的 swiftkey 键盘有关(我从问题中删除了它)。位图错误与背景图片有关
  • @user1692261 我回滚了这个问题,因为你删除该行会使我的答案无效 - 人们会认为这是一个糟糕的回应。
【解决方案2】:

我在 genymotion API 16+ 上的模拟设备上也遇到过这个错误。

我的问题的解决方案是将 gif 图像替换为 png 图像。

感谢http://www.pedrorainho.eu/eopenglrenderer2268-cannot-generate-texture-from-bitmap/

【讨论】:

    【解决方案3】:

    我在使用 Android L 版本的 nexus5 中遇到了同样的错误。 就我而言,我评论了两行来修复它。 ( // opt.inPurgeable = true; // opt.inInputShareable = true; ) 希望对你有用。 祝你好运!

    下面是我的代码:

    ImageView image = (ImageView) findViewById(R.id.imageView);
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inPreferredConfig = Bitmap.Config.RGB_565;
    //        opt.inPurgeable = true;
    //        opt.inInputShareable = true;
            
            InputStream is = getResources().openRawResource(R.raw.error_nothing_app);
            Bitmap bitmap = BitmapFactory.decodeStream(is, null, opt);
            is.close();
            BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
            image.setImageDrawable(drawable);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 2011-01-23
      • 2017-07-04
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      相关资源
      最近更新 更多