How can I just upload an image with a universal image downloader

As far as I know, the universal image downloader provides 2 kinds of methods for displaying images. imageLoader.loadImage and imageLoader.displayImage. But these 2 methods must bind to the user interface element for display. Can I just upload cache files to the stream (for future display). I do not need to display these images right now.

+8
android universal-image-loader
source share
4 answers

Is it possible to simply upload files to the cache in the stream (for future display). I do not need to display these images right now.

You can upload files using Executor or create a stream. You do not need to use a universal image downloader.

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

You can also use DownloadManager and save the file to the SD card. You can get 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 images to a folder on the SD card.

Bitmap Caching

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

You cache bitmaps in memory or on disk. The link contains information about the topic.

Basically you use UIL ofr displaying images in listview or grdiview. To use the UIL in a list view or gridview, you can do as shown below.

https://github.com/nostra13/Android-Universal-Image-Loader . It is based on the Lazy List (works on the same principle). But it has many other configurations. You can display an error image if downlaod failed. Can display images with rounded corners. Can cache disk 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 customize other options to suit your needs.

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

+5
source share

You can use UIL . Based on the displayOptions used below, images will be cached.

See here - https://github.com/nostra13/Android-Universal-Image-Loader

// Load the image, decode it in Bitmap and return Bitmap for callback

 imageLoader.loadImage(imageUri, displayOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { // Do whatever you want with Bitmap } }); 
+11
source share

Theres loadImage(String uri, ImageLoadingListener listener) , I think you can call it null for the listener if you don't need it.

+2
source share

Adding to @Robin Srivastava answer:

You must also create an instance of the ImageLoader context, for example: imageLoader = ImageLoader.getInstance(); before you can use the loadImage method. The displayOptions parameter displayOptions also optional, so you can exclude it if necessary.

0
source share

All Articles