Best way to download images on Android - java

I'm developing an Android application which uses several images and I would like transfer bigger images (2-6 MB) on a web server to download them when need.
I've never tried it before so I've found a method which uses AsyncTask to download images on button click, is this the best solution?
Any better options or opinions?
EDIT: I'm trying koush's ion
EDIT 2: I tried ion (https://github.com/koush/ion) and I like it here very well, very easy to use. advised

Use Universal image loader for downloading images asynchronously.
[https://github.com/nostra13/Android-Universal-Image-Loader][1].
The Library itself has a sample code to download image.you may refer it..
[1]: https://github.com/nostra13/Android-Universal-Image-Loader
After downloading library add library with your project and insert the below code at necessary place
String final_url="www.google.com/.....";
ImageView image;
ImageLoader imageloader = ImageLoader.getInstance();
imageloader.init(ImageLoaderConfiguration.createDefault(context));
DisplayImageOptions options; = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.resetViewBeforeLoading(true).cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
.cacheInMemory(true)
.displayer(new FadeInBitmapDisplayer(300)).build();
imageloader.displayImage(final_url, image);

I strongly recommend to use Glide or Picasso, which are the most used libraries nowadays.
Just google "Glide for Android" or "Picasso for Android" and they take care of the threading, caching, optimization, etc.
I hope it helps!

Best practice:
http://developer.android.com/training/displaying-bitmaps/index.html.
Useful libraries:
Picasso - http://square.github.io/picasso;
Glide - github.com/bumptech/glide.

Actually the most important reason to useAsyncTask is that you want a mechanism to do a lengthy operation with out blocking your UI. With it you also get rid of managing child thread and synchronization. And that's it. If you want other functionalities, such as bitmap caching, you will have to implement on your own or use some third-party tools.

Use lazy loading images for this and use image caching.This is the best way to do it.
https://github.com/thest1/LazyList
http://androidexample.com/Download_Images_From_Web_And_Lazy_Load_In_ListView_-_Android_Example/index.php?view=article_discription&aid=112&aaid=134
http://sunil-android.blogspot.in/2013/09/lazy-loading-image-download-from.html
You can find some more examples for lazyloading.Hope the above links are also useful.

Related

AWS S3 and Cloudfront for storage of images

I'm using AWS S3 for storage my images and accessing them by Cloudfront. Here is mine access url formate. For example:
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg
I want to use thumbnail for this image. Generating thumbnails at upload time is not modern approach especially when you are required a lot of different size images. It's not good in maintenance point of view. A little change in design required to regenerate all of thumbnails again.
Is there any possibility for thumbnail image to be generated on the fly by just requesting a URL something like below:
http://mybucket.s3.amazonaws.com/thumb/200/150/qGdyRHeptWqR5sl.jpg
OR
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg?size=200x200
OR
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg?width=200&height=200
I've tried all the above url but no success. DO i need to use some image resizing plugin to do so? Do i need to request image from cloudefront & resize it then reupload it on S3?
I'm using Java as programming language please recommend me some plugin or better approach in this case.
One of possible solutions related to ngx_http_image_filter_module plugin for Nginx. You can install Nginx and configure it to resize images from S3 by request.
Here is article which describe how to do it.

Picasso vs. Setting src to ImageView via XML

Is there a difference between using Picasso to put an image into an ImageView and just using android:src in the xml of the imageview? Right now I have an app that contains about 500 images, and I set them all using android:src in XML. Should I be using Picasso for something like this? Am I wasting precious memory?
Picasso is mainly used to load image from the network. You all your images are resources of your application; you can safely set them in the XML.
I think there may still be some advantages to using picasso even for loading local resources. I think you would still get the caching which might speed up certain operations. For example maybe you get a memory cached image when you switch back and forth between two activities, or scroll in and out of view.
The following is from the Picasso web site. I am thinking Square saw some value in this otherwise I don't know that they would have implemented this.
RESOURCE LOADING
Resources, assets, files, content providers are all supported as image sources.
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load(new File(...)).into(imageView2);

How to use BufferedImage in android for apache.common.imaging

i am using a method from the apache.common.imaging in which the BufferedImage is used, i know that BufferedImage is not part of the android classes since awt package is not available but i need bufferedimage for that method any ways to achieve this?
The method is as follows:
JpegImageParser parser= Imaging.getBufferedImage(sourceFile);
you can find the source of the library here is there a way to port that project or any workaround to get this method working?
Android has other libraries that provide this functionality. In particular, Picaso is quite popular and easy to use.

gdx parse layout files to object files

we use libgdx for graphics rendering for our game on android. Seems like libgdx can drop support for layout files in the future. Disadvantages of using layout file is that it take longer to parse it. Advantages being it is very convenient to build UI using it instead of building UI in java files.
So I would like to know if there is a way to parse layout into serializable object files and load these object files in the game instead of layout files. This way if we can maintain a utility, using old gdx library which produces object files from layout files and upgrade gdx in out actual game.
edit : the layout files are of libgdx's not android's
There currently isn't any way to serialize your layout information with libgdx. You will likely need to write your own wrappers and somehow store this layout information, as I don't know of anyone who has done this. If you are using an old version of the library, which still has the tablelayout files, I'm not sure how easy it will be considering the amount of changes which has been made to libgdx since that time. The alternative is to re-write you files using the Java api, which you will likely need to do going forward.
I am not sure how you are still using the tablelayout ui files. They have been deprecated for over a year now and are not included with any of the latest releases of libgdx. If you want a more detailed explanation on what happened to the layout files you can look at this post. I do miss the layout files because of the extra bloat created by having to code the ui formatting. However, I also find you get much finer control over dynamic layouts by using the Java api.

Handle images in JSF

I am currently developing a website in which several images will be displayed on a single page. In light of performance, I'm searching for the best way to handle thes images.
First, I will explain my needs. The back-end of the website consists of a CMS in which images can be uploaded (and maybe resized by the user so the image will have the neede ratio of width/height). These images will be displayed on several pages in de website, requested by (hopefully) many users.
Secondly, I will shortly describe my environment. I am developing in Java EE, using JSF as front-end. I am using multiple libraries like Prime Faces et cetera.
I have done some research and it seems there are dozens of solutions, but I don't know in which direction to search. E.g.:
Saving images in database
Saving images as static images by using for example filestreams
So in short:
Which way of saving and requesting images would be best in this case?
What library would you advice to serve me in this?
Is there a JSF-solution to manually resize images?
Would ImageJ be the best solution to generate thumbnails? If not, what would be?
If any other details are needed, I'm happy to provide them.
Thanks in advance.
I wouldn't worry about performance until it becomes an issue. I would perhaps worry more about auditability, maintainability etc.
In order to make a future change easy, however, is abstract away your image store such that you can easily replace (say) a file-based system, with a database system (or a cloud-storage solution, or, or...).
That way you can easily substitute one for another and compare/constrast if need be, or simple swap out your implementation at a later date.
So..
Saving images as files is best
After some research it seems that PrimeFaces offers ImageCropper
File Upload can be achieved using PrimeFaces' FileUpload
But still, I have seen many discussions on Image Manipulation by Java and the best tooling for this. Some say ImageJ would be great, others don't. Is there any reason why I should go with one or another?

Categories

Resources