我怎么能只下载图像的通用图像装载机 [英] How can i just download image with universal-image-loader

查看:153
本文介绍了我怎么能只下载图像的通用图像装载机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,通用的图像加载器提供200种方法来显示图像。 imageLoader.loadImage和imageLoader.displayImage。但是,这些2种方法必须绑定到用户界面元素显示。我可以下载文件缓存在一个线程(对于未来显示器)。我不需要现在来显示这些图像。

解决方案
  

我可以下载的缓存文件在一个线程(对于未来显示器)。   我不需要现在来显示这些图像。

您可以下载使用遗嘱执行人或创建一个线程文件。你并不需要使用通用ImageLoader的。

<一个href="http://developer.android.com/reference/java/util/concurrent/Executor.html">http://developer.android.com/reference/java/util/concurrent/Executor.html.

您还可以使用下载管理器,并将文件保存在SD卡。您可以供以后使用检索相同的。

<一个href="http://oodlestechnologies.com/blogs/Downloading-and-Retrieving-Files-on-SD-card-in-Android-using-Android-SDK-in-Eclipse">http://oodlestechnologies.com/blogs/Downloading-and-Retrieving-Files-on-SD-card-in-Android-using-Android-SDK-in-Eclipse

要缓存的位图,你可以在SD卡写入图像到一个文件夹。

缓存位图

<一个href="http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html">http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html.

您缓存在内存或磁盘位图。链接有关于该主题的详细信息。

您主要使用UIL OFR显示在列表视图或grdiview图像。要使用UIL在列表视图或GridView中,你可以做如下图所示。

<一个href="https://github.com/nostra13/Android-Universal-Image-Loader">https://github.com/nostra13/Android-Universal-Image-Loader.它是基于懒列表(在相同的原则也适用)。但它有许多其它配置。您可以显示一个错误的形象,如果立即下载失败。可以显示圆角的图像。可以缓存光盘或记忆。 CAN通讯preSS形象。

在自定义适配器的构造函数

 文件cacheDir = StorageUtils.getOwnCacheDirectory(一,你的文件夹);

 //获取ImageLoader的的singletone实例
 ImageLoader的= ImageLoader.getInstance();
 //创建配置ImageLoader的(所有选项都是可选)
 ImageLoaderConfiguration配置=新ImageLoaderConfiguration.Builder(一)
      //你可以通过你自己的内存缓存实现
     .discCache(新UnlimitedDiscCache(cacheDir))//你可以通过你自己的盘缓存实现
     .discCacheFileNameGenerator(新的Hash codeFileNameGenerator())
     .enableLogging()
     。建立();
 //初始化ImageLoader的使用创建的配置。做一次。
 imageLoader.init(配置);
 选项​​=新DisplayImageOptions.Builder()
 .showStubImage(R.drawable.stub_id)//显示存根图像
 .cacheInMemory()
 .cacheOnDisc()
 .displayer(新RoundedBitmapDisplayer(20))
 。建立();
 

在你的getView()

  ImageView的形象=(ImageView的)vi.findViewById(R.id.imageview);
 imageLoader.displayImage(IMAGEURL,图像,选项); //提供IMAGEURL,ImageView的和选项
 

您可以与其他选项进行配置以满足您的需求。

随着延迟加载/通用图像装载机,您可以查看支架的平滑滚动和性能。 <一href="http://developer.android.com/training/improving-layouts/smooth-scrolling.html">http://developer.android.com/training/improving-layouts/smooth-scrolling.html.

as far as I know, universal-image-loader provide 2 kinds of methods to display images. imageLoader.loadImage and imageLoader.displayImage. But those 2 methods must bind to UI element to display. Can I just download files for cache in a thread (for future display). I don't need to display those image right now.

解决方案

Can I just download files for cache in a thread (for future display). I don't need to display those image right now.

You can download files using Executor or creating a thread. You don't need to use universal imageloader.

http://developer.android.com/reference/java/util/concurrent/Executor.html.

You can also use a DownloadManager and save the file in sdcard. You can retrieve the same for later use.

http://oodlestechnologies.com/blogs/Downloading-and-Retrieving-Files-on-SD-card-in-Android-using-Android-SDK-in-Eclipse

To cache bitmaps you can write the images to a folder in sdcard.

Caching bitmaps

http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html.

You cache bitmaps in memory or disk. The link has details regarding the topic.

You basically use UIL ofr displaying images in listview or grdiview. To use UIL in listview or gridview you can do as below.

https://github.com/nostra13/Android-Universal-Image-Loader. It is based on Lazy List(works on same principle). But it has lot of other configurations. You can display a error image if downlaod failed. Can display images with rounded corners. Can cache on disc or memory. Can compress image.

In your custom adapter constructor

 File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder");

 // Get singletone instance of ImageLoader
 imageLoader = ImageLoader.getInstance();
 // Create configuration for ImageLoader (all options are optional)
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
      // You can pass your own memory cache implementation
     .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
     .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
     .enableLogging()
     .build();
 // Initialize ImageLoader with created configuration. Do it once.
 imageLoader.init(config);
 options = new DisplayImageOptions.Builder()
 .showStubImage(R.drawable.stub_id)//display stub image
 .cacheInMemory()
 .cacheOnDisc()
 .displayer(new RoundedBitmapDisplayer(20))
 .build();

In your getView()

 ImageView image=(ImageView)vi.findViewById(R.id.imageview); 
 imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options

You can configure with other options to suit your needs.

Along with lazy loading/Universal Image Loader you can view holder for smooth scrolling and performance. http://developer.android.com/training/improving-layouts/smooth-scrolling.html.

这篇关于我怎么能只下载图像的通用图像装载机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆