【问题标题】:Universal Image Loader (UIL) makes the images too small when loaded into image views通用图像加载器 (UIL) 使图像在加载到图像视图时变得太小
【发布时间】:2017-01-31 01:26:50
【问题描述】:

我正在尝试在我的测试项目中使用通用图像加载器 (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

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

【问题讨论】:

标签: java android xml imageview universal-image-loader


【解决方案1】:

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

.diskCacheExtraOptions(480, 320, null)

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

重要提示:使用时

.cacheOnDisk(true)

在再次运行程序之前删除模拟器/手机上的缓存/数据(为了确定,我通常会删除整个应用程序并在下次运行时重新安装它)。似乎 UIL 不会在以后下载更高质量的图像版本,因为它们之前已经被缓存,无论它们的质量如何。

希望这对某人有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2018-11-20
    • 2017-04-07
    • 2013-09-16
    相关资源
    最近更新 更多