我之前没有成功地使用过相同的图片。这种行为似乎是错误的,或者至少对我来说很奇怪。
我的代码和堆栈跟踪:
应用:
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
?
我认为这可能是一个错误,或者我错过了什么?
如果这不是错误,我该怎么做才能解决?
答案 0 :(得分:1)
当我遇到类似的问题时,我在GitHub上遇到了this issue。问题似乎涉及到centerCrop,它想要在裁剪之前使用大于目的地的图像。我无法解释为什么调试日志使用缩小的图像显示它,但我可以说,在我的情况下,我通过向DisplayImageOptions添加以下内容来实现它:
.imageScaleType(ImageScaleType.EXACTLY)
GitHub问题还表明,FIT_CENTER
,FIT_XY
,FIT_START
,FIT_END
和CENTER_INSIDE
的ScaleType会表现得更好。