【问题标题】:Universal Image Loader loading half images or partial images通用图像加载器加载半图像或部分图像
【发布时间】:2015-03-22 05:09:59
【问题描述】:

我在我的应用程序中使用通用图像加载器库。我遇到了一个奇怪的问题,有时在某些 Android 手机上它只加载半张图片,就像我附上了图片一样。

这是我的配置:

public static void initImageLoader(Context context) {

        // This configuration tuning is custom. You can tune every option, you
        // may tune some of them,
        // or you can create default configuration by
        // ImageLoaderConfiguration.createDefault(this);
        // method.
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context)
                .threadPriority(Thread.NORM_PRIORITY - 1)
                .threadPoolSize(3)
                // default
                // .denyCacheImageMultipleSizesInMemory()
                .discCache(

                        new FileCountLimitedDiscCache(new File(
                                Constant.EXTERNAL_STORAGE_PATH_FOR_LAZY), 100))
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
                // discCache(new TotalSizeLimitedDiscCache(new
                // File(Constant.EXTERNAL_STORAGE_PATH_LAZY), 10))
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                .discCacheFileCount(100)
                // .discCacheSize(1 * 512 * 1024)
                .build();
        ImageLoader.getInstance().init(config);
    }

}

【问题讨论】:

  • 如果您使用描述性较低的配置会发生什么? (删除所有设置缓存大小等的覆盖,然后对其进行初始化)。您还确定图像没有损坏吗?要检查的另一件事是它是否尊重exif 参数。尝试设置考虑Exif(或类似的东西),看看是否有帮助。
  • 如果我使用较少描述性的配置,那么结果也是一样的。
  • 您可以粘贴包含图像视图的布局 xml 吗?问题可能存在,而不是图像加载器。还可以尝试将图像保存在 SD 卡位置(在通过 UIL 加载之前)并在图库中查看以确保图像本身没有损坏。
  • 我注意到问题可能是解码位图
  • 从广场使用毕加索图书馆怎么样?

标签: android universal-image-loader


【解决方案1】:

你可以试试这个:

  1. 编译这个依赖:compile 'com.koushikdutta.ion:ion:2.+'
  2. 修改您的适配器或图像视图,如:

这个

Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.animateLoad(spinAnimation)
.animateIn(fadeInAnimation)
.load("http://example.com/image.png");

基于此example

希望对你有帮助!!!

【讨论】:

    【解决方案2】:

    使用Glide。我用这个代替 UIL 并推荐给你。

    【讨论】:

      【解决方案3】:

      在下载图像时使用监听器,在该监听器中您可以在onLoadingComplete() 中完成您的工作。

      这里是示例代码:

      imageLoader.loadImage(url, new SimpleImageLoadingListener(){
      
                      @Override
                      public void onLoadingComplete(String imageUri, View view,
                              Bitmap loadedImage) {
                      super.onLoadingComplete(imageUri, view, loadedImage);
      
                          //write your code here to use loadedImage
                      }
      
                  });
      

      此代码将帮助您识别图像何时完全下载。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-07
        • 2019-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多