通用图像加载器 (UIL) 使图像在加载到图像视图时太小

Universal Image Loader (UIL) makes the images too small when loaded into image views

我正在尝试在我的测试项目中使用通用图像加载器 (UIL),但我认为当图像的高度大于宽度时我无法加载图像。 UIL 加载到我的图像视图的图像太小,即使图像实际上尺寸很大。因此,当我拉伸我的图像视图以匹配它们的父视图时,图像看起来严重模糊且质量低下。

但是当图像的高度小于或等于它们的宽度时,UIL 会正确加载我的图像。

这是我的 java 代码:

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheOnDisk(true)
            .imageScaleType(ImageScaleType.NONE)
            .bitmapConfig(Bitmap.Config.ARGB_8888)
            .build();
File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .defaultDisplayImageOptions(defaultOptions)
            .threadPoolSize(1)
            .diskCache(new UnlimitedDiskCache(cacheDir))
            .diskCacheExtraOptions(480, 320, null)
            .build();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);

String imageURL;

ImageView imageView1 = (ImageView)findViewById(R.id.imageview1);
imageURL = "http://www.up.edu.ph/wp-content/uploads/2017/01/twsc-40th-posters-WEB-01.png";
imageLoader.displayImage(imageURL, imageView1);

ImageView imageView2 = (ImageView)findViewById(R.id.imageview2);
imageURL = "http://www.up.edu.ph/wp-content/uploads/2017/01/UPD-Chancy-Selection1.png";
imageLoader.displayImage(imageURL, imageView2);

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ph.edu.up.e.universalimageloadersample.MainActivity"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/imageview1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/imageview2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

这是通过 UIL 加载图像时的样子:

imageView1

imageView2

请不要推荐任何其他图片加载器。除此之外,任何帮助将不胜感激。谢谢!

我犯了一个愚蠢的错误,但我终于找到了解决办法。使用时要小心:

.diskCacheExtraOptions(480, 320, null)

无论您的图像缩放类型是什么,它都可能会降低您的图像质量。

重要提示:使用

.cacheOnDisk(true)

在您的 emulator/phone 上删除 cache/data,然后再 运行 重新安装您的程序(为了确定,我通常会删除整个应用程序并在我的下一个 运行 上重新安装]).似乎 UIL 不会在之前缓存过图像后下载质量更好的图像版本,无论它们的质量如何。

希望这对某人有所帮助