I want to download images with universal image loader but I do not want it to decode the images and create bitmap from it. I just want to save the original image in a directory. how can I disabling it to decode?
Can I use other libraries? for example picasso but I think it can not do that, am I right?
I think the answer would be:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.NONE)
.build();
because of:
public enum ImageScaleType {
/** Image won't be scaled */
NONE,
from
https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/library/src/com/nostra13/universalimageloader/core/assist/ImageScaleType.java#L24
Related
I'm trying to load an image from the following url:
https://fangkarte.de:8080/fangfisch/file/files/592036af55dfffca0155e01fe10002f7
In Chrome/IE the image will be displayed without problems. When I try to load the image on Android I am not able to store the image as an PNG file. Everytime the image will be saved as a textfile which contains the image as base64 String.
Also I tried the following code but the decodedByte is null:
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Does anyone have an idea how I can show my image from the url as an bitmap or which I prefer to store the image on the device as an png?
Use Universal Image Loder to upload image from Url
Download universal image loder and add to your lib folder and
Implement the below code where you want to load image
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.noimage)
.showImageOnFail(R.drawable.icon3)
.showImageOnLoading(R.drawable.loading).build();
imageLoader.displayImage(url, imageview, options);
For handling images, Use Picasso , Glide , Universal image loader, Volley or Fresco
Eg, in picasso, you will be able to load images, store them in memory cache and handle cancellations in listviews/recyclerviews etc...
Picasso.with(context).load("https://fangkarte.de:8080/fangfisch/file/files/592036af55dfffca0155e01fe10002f7").placeholder("someimagetillyourimagedownloads).into(R.id.yourimageview);
Picasso: https://github.com/square/picasso
Glide: https://github.com/bumptech/glide
Fresco: https://github.com/facebook/fresco ( I use this after extensively testing all 3 except volley )
UIL: https://github.com/nostra13/Android-Universal-Image-Loader
Similar things can be done using all the above libraries.
I highly recommend not trying to handle images on your own. It can turn into quite a mess if you are a novice android dev.
The image you download is much to big ((860.000 bytes)) to make a Bitmap out of it. So BitmapFactory will return null.
Scale image down before use.
I have a screen with an ImageView containing the actual profile picture. I can edit that profile picture either by taking a picture with the camera or by picking a picture from the sd card. I store the new chosen profile picture under the same path as the old (i overwrite it) which is logical i guess.
However when i set a new profile picture to my ImageView it does not get refreshed. I have to restart the App to see the change.
this.imageView.invalidate();
is what all people are telling me to do when i brows google but no, this is not working! So how can i force my imageview to load the new profile picture?
I load the image into the ImageView with help of Picasso:
Picasso picasso = Picasso.with(context);
if(reload) {
picasso.invalidate(new File(fileName));
}
RequestCreator requestCreator = picasso.load(new File(fileName));
requestCreator.into(imageView);
Picasso caches loaded images to speed up the loading process. This means that if you are trying to reload the same exact picture it loads the cached version and it does not read the changed File from the disk.
You need to tell Picasso that the picture has changed and that it needs to reload the picture from the disk by invalidating the cache. The way you do this is like this:
File file = new File(fileName);
Picasso picasso = Picasso.with(context);
picasso.invalidate(file);
picasso.load(file).into(imageView);
To skip Picasso's cache, you can use .memoryPolicy(MemoryPolicy.NO_CACHE) static method:
Picasso
.with(context)
.load(file)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.into(imageView);
I'm using universal image loader.
I want to download a picture from url and show it in my application.
I'm sure that i'll never change the picture in my site.
So I need it to be downloaded once. and don't even check the date of modification to download it.
In fact I want the app to check if the image was downloaded the don't download it :)
How can I do this.
Thank you
instead of download image you should keep in drawable and use it
if you are download image via UID its save in catch memory and it is removable you can clear that catch once it is clear than you have to download again if you sure that you want download once only than i suggest go for drawable not for UID unless you have specific requirement
On universal loader if you are true cacheInMemory then it maintain cache and your image download once. By default it is false:-
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
...
.cacheInMemory(true)
.cacheOnDisk(true)
...
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.defaultDisplayImageOptions(defaultOptions)
...
.build();
ImageLoader.getInstance().init(config);
for more info you have to read below link:-
https://github.com/nostra13/Android-Universal-Image-Loader
This question already has answers here:
How to load an ImageView by URL in Android?
(23 answers)
Closed 9 years ago.
I have Imageview and a link to the picture on the Internet. I set this picture to the ImageView like this,
public ImageView iv;
iv = (ImageView) findViewById(R.id.imageView);
String img = "https://www.google.com/images/srpr/logo11w.png";
iv.setImageDrawable(Drawable.createFromPath(img));
What I want to do is download a picture from the internet to my android application and apply it to an ImageView. I want to make it as easy as possible.
helped me
String img_url= //url of the image
URL url=new URL(img_url);
Bitmap bmp;
bmp=BitmapFactory.decodeStream(url.openConnection().getInputStream());
ImageView iv=(ImageView)findviewById(R.id.imageview);
iv.setImageBitmap(bmp);
There many libs to do this, my favourite is Picasso.
Here an example of usage:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
give it a try :)
This method create a Drawable from file path name.
Check this answer.
There are many libraries available on doing this, I recommend using a library, because a they have many extra options availble.
Take Universal Image Loader
Features
Multithread image loading
Possibility of wide tuning ImageLoader's configuration (thread executors, downloader, decoder, memory and disc cache, display image options, and others)
Possibility of image caching in memory and/or on device's file system (or SD card)
Possibility to "listen" loading process
Possibility to customize every display image call with separated options
Widget support
Possibility to show an custom Image on loading, error, etc.
You have to set the options one time using:
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.build();
ImageLoader.getInstance().init(config);
Then, lateron you can use this anywhere in your code:
ImageView iv = (ImageView) findViewById(R.id.imageView);
String str = "http://google.com/img.jpg";
ImageLoader.getInstance().displayImage(str, iv);
Ofcourse there are many other libraries you can use like picasso, Smart Image View, Url Image View and many others.
I can't find in any really credible source explaining what LazyList is. Anyone?
Lazy List is lazy loading of images from sd-card or from server using urls. It is like on demand loading of images.
Images can be cached to a local sd-card or your phone's memory. URL is considered the key. If the key is present in the sd-card, images get displayed from sd-card, otherwise it downloads the image from the server and caches it to a location of your choice. You can set a cache limit. You can also choose your own location to cache images. Cache can also be cleared.
Instead of the user waiting to download large images and then displaying them, lazy list loads images on demand. Since images are cached, you can display images offline.
https://github.com/thest1/LazyList. Lazy List
In your getview
imageLoader.DisplayImage(imageurl, imageview);
ImageLoader Display method
public void DisplayImage(String url, ImageView imageView) //url and imageview as parameters
{
imageViews.put(imageView, url);
Bitmap bitmap=memoryCache.get(url); //get image from cache using url as key
if(bitmap!=null) //if image exists
imageView.setImageBitmap(bitmap); //display iamge
else //downlaod image and dispaly. add to cache.
{
queuePhoto(url, imageView);
imageView.setImageResource(stub_id);
}
}
An alternative to Lazy List is Universal Image Loader
https://github.com/nostra13/Android-Universal-Image-Loader. It is based on Lazy List (it works on the same principle), but it has lot of other configurations. I would prefer to use Universal Image Loader because it gives you more configuration options. It can display an error image if a download failed. It can display images with rounded corners. It can cache on disc or memory. It can compress an 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 Universal Image Loader with other options to suit your needs.
Along with LazyList/Universal Image Loader you can view this website for smooth scrolling and performance.
http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
AFAIK, I'll explain you with the example
If you list contain lot of images with Text, it will take some time for your list to load because you need to download images and you need to populate them in the list. Suppose if your list contains 100 images It will take lot of time to download each image and to show it the listitem. To make the user wait until the images loads is not user friendly.
so What we need to do. At this point of time lazy list comes into picture. It is the idea that let the images be loaded in background and show text mean while.
Everybody know that listview recycle its views for every view. i.e if your listview contains 40 elemtns then listview won't allocate memory for 40 items instead it allocate memory for the visible items, i.e say you can see only 10 items at a time. so listview will allocate 10 items meemory.
So When ever you scroll the view, then the view will refresh. because of the you'll lose your reference to images and you need to download them agian. in order to avoid that, caching comes into picture.
This example is based on my knowledge in listview, I am not saying this is only correct. There might be wrong in the answer, if any body find feel free to inform me.
I think this is the other way around. AFAIK, Lazy Loading is the definition, where you actually load the data only when you need it, and it's a good design practice.
So I believe the same applies for this, only this time it's being referring to the List View.
If I'm wrong, please correct me.
The best example of lazy list is facebook notifications,messages,requests. when you scroll then data will be load.