What is the laziest method to get JPEG from url and get it to use in my app? I would like to achieve it without any new libraries to my project.
Sincerely, Peter.
On
You can also use ImageLoader
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300)).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.discCacheSize(100 * 1024 * 1024).build();
ImageLoader.getInstance().init(config);
//your image url
String url = "http://javatechig.com/wp-content/uploads/2014/05/UniversalImageLoader-620x405.jpg";
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(fallback)
.showImageOnFail(fallback)
.showImageOnLoading(fallback).build();
//initialize image view
ImageView imageView = (ImageView) findViewById(R.id.imageView1)
//download and display image from url
imageLoader.displayImage(url, imageView, options);
For more details , you can visit this post ImageLoader
but beware you can't run this code on
UI Thread, it should be done onThreadorAsyncTask