【问题标题】:Bitmap too large to be uploaded into a texture (Universal Image Loader)位图太大而无法上传到纹理中(通用图像加载器)
【发布时间】:2014-02-03 05:46:01
【问题描述】:

我之前已经成功使用过同一张图片,没有任何问题。这种行为似乎是错误的,或者至少对我来说很奇怪。

  • UIL 版本:GitHub,2014 年 1 月 28 日提交
  • Android 版本:4.3 (Galaxy Nexus)

我的代码和堆栈跟踪:

应用:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).writeDebugLogs().build();
ImageLoader.getInstance().init(config);

片段:

String imageURI= "http://cdn.screenrant.com/wp-content/uploads/A-Stormtrooper-lost-in-the-desert.-2560x1080-Imgur.jpg";
DisplayImageOptions options = new DisplayImageOptions.Builder()
             .cacheInMemory(true)
             .cacheOnDisc(true).build();
ImageLoader.getInstance().displayImage(imageURI, imageView, options);

xml:(这应该是 AlertDialog 的 customTitle):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="64dp" >

    <ImageView
        android:id="@+id/clue_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/clue_title"
        android:layout_alignLeft="@+id/clue_title"
        android:layout_alignRight="@+id/clue_title"
        android:layout_alignTop="@+id/clue_title"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/trooper"
        tools:ignore="ContentDescription" />

    <TextView
        android:id="@+id/clue_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="#B3000000"
        android:ellipsize="end"
        android:gravity="start|center_vertical"
        android:minHeight="64dp"
        android:paddingBottom="5dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="5dp"
        android:text="@android:string/untitled"
        android:textAlignment="viewStart"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white" />

</RelativeLayout>

堆栈跟踪:

02-03 00:11:48.343: D/ImageLoader(6701):    Start display image task [http://cdn.screenrant.com/wp-content/uploads/A-Stormtrooper-lost-in-the-desert.-2560x1080-Imgur.jpg_720x1184]
02-03 00:11:48.343: D/ImageLoader(6701):    Load image from disc cache [http://cdn.screenrant.com/wp-content/uploads/A-Stormtrooper-lost-in-the-desert.-2560x1080-Imgur.jpg_720x1184]
02-03 00:11:48.398: D/dalvikvm(6701):       GC_FOR_ALLOC freed 922K, 3% free 34681K/35664K, paused 51ms, total 51ms
02-03 00:11:48.476: I/dalvikvm-heap(6701):  Grow heap (frag case) to 49.525MB for 16384016-byte allocation
02-03 00:11:48.507: D/dalvikvm(6701):       GC_FOR_ALLOC freed 1K, 2% free 50679K/51668K, paused 32ms, total 32ms
02-03 00:11:48.875: D/ImageLoader(6701):    Cache image in memory [http://cdn.screenrant.com/wp-content/uploads/A-Stormtrooper-lost-in-the-desert.-2560x1080-Imgur.jpg_720x1184]
02-03 00:11:48.875: D/ImageLoader(6701):    Display image in ImageAware (loaded from DISC_CACHE) [http://cdn.screenrant.com/wp-content/uploads/A-Stormtrooper-lost-in-the-desert.-2560x1080-Imgur.jpg_720x1184]
02-03 00:11:48.882: W/OpenGLRenderer(6701): Bitmap too large to be uploaded into a texture (2560x1600, max=2048x2048)

如果我没记错的话,这张图片已经缩小到720x1184 的大小。如果这是真的,那么为什么要尝试使用原始图像2560x1600?

我认为这可能是一个错误,还是我遗漏了什么?

如果这不是错误,我能做些什么来解决它?

【问题讨论】:

    标签: android bitmap android-imageview universal-image-loader


    【解决方案1】:

    当我遇到类似的问题时,我在 GitHub 上遇到了this issue。问题似乎涉及 centerCrop,它希望在裁剪之前使用大于目标的图像。我无法解释为什么调试日志使用按比例缩小的图像显示它,但我可以说,就我而言,我通过将以下内容添加到 DisplayImageOptions 来使其工作:

        .imageScaleType(ImageScaleType.EXACTLY)
    

    GitHub 问题还表明,FIT_CENTER、FIT_XY、FIT_START、FIT_END 和 CENTER_INSIDE 的 ScaleType 会表现得更好。

    【讨论】:

      猜你喜欢
      • 2012-05-03
      • 2015-04-05
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多