So i´m creating a app in Android which stores images in a external server. I want to know where is better to make the optimization of the image file, in server, or give the non-optimize image to local and then optimize inside the app. Im using mysql for store the images, but if its better to use sqlite server i will change it. Thanks.
The best thing to do here is create an application on your server exposed through an API with query parameters to specify image sizes + caching mechanism.
For example:
www.mywebsite.com/imageloader/file-identifier?width=50&height=50&format=png
then implement a caching mechanism take a look at (https://dev.mysql.com/doc/refman/5.1/en/ha-memcached.html) for mysql on the server for this image using these parameters so the application can quickly return this file each time and not require too much work from the application. This will allow you to request multiple images at specific sizes when you need them for example only as a thumbnail... Or a full Gallery image which can be something much larger.
Additionally you will want to use an Image Library and there are certainly quite a few for Android (to name a few):
Picasso from Square http://square.github.io/picasso/
Fresco from Facebook https://github.com/facebook/fresco
Ion from this Github https://github.com/koush/ion
These can all help you format your images and cache them locally and even downsize the images as necessary.
Related
I am able to handle images and text from web URL's in android using AsyncTask, but have a separate question in mind.
Which approach is best suited for storing pictures for one time loading?
IE: Either in an SD Card or in SQLite DB.
If you want to store images for just one time loading, you don't need to store it in Sdcard. You better use a library like Glide or Picasso. It does all the hard work of caching and managing memory for you. It has very simple API.
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
I want to save the images fetched from server for once and from next time i want to check first whether images are stored or not in device, if not then again it should fetch from server and store in user's device again, and if yes then application will use images directly rather than fetching from server again and again. It will be useful for enhancing the speed of application. Basically my application is fetching multiple images from server so i want to save those images on user's android device and from next time application should fetch from device. I think you got my question.
The simple way:
You can use Picasso.
It is a simple lib which provides image downloading and caching.
In my opinion it might not be the fastest, but it is pretty simple and intuitive. It does its job well and none who I asked complained about it.
Picasso
Other libs:
UIL
Volley
Glide
fresco
To make it short. There are lots of other libs. An awesome comparision of the most Populat ones can be found here and here
The do it yourself way:
You can also write you own caching logic with a LRUCache. Which is also pretty simple.
Take a look at:
https://developer.android.com/topic/performance/graphics/cache-bitmap.html
The LRUCache is just a Memory Cache so you might also want to use a DiskLRUCache
I have an app where people can set pictures as wallpaper but its really slow because pictures are very big. This app load pictures and then when i want to see it again it has to load again.
What to do to make it faster? I use Json service. My pictures are from server. i am using universal image loader.
Theres 2 types of cache in android, the memory cache and the disk cache. You should use picasso its a library that implement both and is very easy to use (1 line of code).
I'm making an android app, here the images are getting from Cloud, is it good idea to download images and save it & use it further. Or download images every-time user uses the app, what idea you prefer is the best?
Because downloading images always is slow & its bad i know but at some point if the images are updated then how to get to know about it?
You should definitely cache your downloaded files!
Do it in your internal app directory where only you do have access to (or otherwise external storage, thats still ok).
Bandwidth and connections are always expensive and should kept low as much as possible.
So your user can see images fast even on a bad connection and your app doesn't waste his valuable bandwidth of a users data plan.
Maybe this could also help you:
https://github.com/novoda/ImageLoader
http://www.androidhive.info/2012/07/android-loading-image-from-url-http/
Make it easy on yourself and use something like Android Smart Image View. It takes care of loading and caching, and it's just about a drop-in replacement for Android's ImageView. Universal Image Loader is another alternative, more configurable, but not as quick to implement.
I used https://github.com/nostra13/Android-Universal-Image-Loader
but I think you not want only download and cache.
these no trick ,if you want check weather the image update or not, you can add metadata for image, just like md5 .
in html and browser, you can set expires header for a image:
enter link description here
but in android app, you control all yourself.
Downloading images and saving them is probably the best way to do it because you don't want to download the same images over and over. If the images are updated you can delete the older one and download the new ones. Just make sure you don't download/save a million images. Take a look at this library. It has a built-in cache on sdcard/external sd.
Downloading images from the net for display, with possible requirement of caching is a very common problem that many people have solved, you can try these solutions to see which fits you:
Ion (https://github.com/koush/ion) - very flexible and feature complete, plus it can download more than images but JSON, Strings, Files, and Java types as well. The part that I really like about this is that it can automatically cancel operations when the calling Activity finishes, so users don't waste time & bandwidth downloading images that will no longer be displayed
Universal Image Loader (https://github.com/nostra13/Android-Universal-Image-Loader) - equally capable for most use cases but for downloading/caching images only
I am making an android app which is going to need a lot of pictures. But I can't have them all in the app since it would be like 10 gigabytes or something. I have read some other questions where they say its smarter to store the url to the pictures in a database. My question is, should the image url be stored in the application itself or in the database?
The DB is a part of the application itself. Is it not? If you are talking about hard-coding , keeping them in DB is better keeping extensibility in mind but would involve extra call to DB.
Hard-coding them would be better performing (How much, you need to test that).
Alternatively you can make use of build tools by storing the urls in a configuration and replacing them at the time of build. While this solves above two problems, It adds complexity to the code.
So everything has its gives and takes, you need to decide what to chose on your requirements and priorities.
If you store the URLs in a database, you are able to manage your images easier, as you don't have to hardcode everything.
store URL in a DB will more preferable. And you can load the images using picasso library would better easier and comfortable way.
Its always better to store image url's in a database, whether that database resides on your phone, or on the server and you fetch it from there using rest services is upto you.
You can use multiple libraries for image lazy loading in your app.
[1]: https://github.com/nostra13/Android-Universal-Image-Loader "Universal Image Loader" is by far a very good third party library.
You can also add your own lazy loading algorithms by creating a basic Thread Pool.