位图过大,无法上传到纹理中(通用图像加载器)

3

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

  • 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呢?
我认为这可能是一个bug,或者是我漏掉了什么?
如果这不是一个bug,我该怎么解决呢?
1个回答

1

当我遇到类似的问题时,我在GitHub上发现了this issue。问题似乎涉及centerCrop,它想使用比目标更大的图像进行裁剪。我无法解释为什么调试日志显示它使用了缩小后的图像,但是我可以说,在我的情况下,我通过将以下内容添加到DisplayImageOptions中使其正常工作:

    .imageScaleType(ImageScaleType.EXACTLY)

GitHub问题还建议使用FIT_CENTERFIT_XYFIT_STARTFIT_ENDCENTER_INSIDE这些ScaleType,效果更佳。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接