Because of the limited mobile phone traffic, when using Android phones, we should consider for users as much as possible to consume less user traffic, in applications, the display of network images is undoubtedly the most traffic-consuming. Therefore, we can compress images or cache images so that images can be obtained only once.
= = = == Options op = op.inSampleSize = 2= = Rect(0, 0, 0, 0= bitmap =
String CACHE_DIR = "/save path of the image on your mobile phone" Map <String, SoftReference <Bitmap> List <Task> isRunning = LogoLoader (Context ctx. ctx = caches = HashMap <String, SoftReference <Bitmap> = ArrayList <LogoLoader. task> isRunning = showImageAsyn (ImageView imageView, String url, = (bitmap =} BitmapDrawable bd = SoftReference <Bitmap> rf = Bitmap bitmap = (bitmap = Task task = (! ImageCallback getImageCallback (BitmapDrawable bd = Handler handler = Task task = Runnable runnable = (taskQueue. size ()> 0 Task task = taskQueue. remove (0 &&! = File ("/mnt/sdcard/jijie/imagecache/" + (file. exists () & file. length ()> 100 = "/mnt/sdcard/jijie/imagecache/" + 10 = 10 = 100 (handler! = Message msg = (= Write (String imageurl, === BufferedOutputStream (0 index = path. lastIndexOf ("/" path. substring (index + 1 netSataus = (cwjManager. getActiveNetworkInfo ()! =
Although the above Code can achieve asynchronous acquisition of images, automatic cache reading, and image compression, It is a headache to process images to adapt to the size of controls, in addition, if a large number of network images are obtained together, a large amount of memory will be occupied, and the system will be released only when the interface is destroyed by default, therefore, it is easy to encounter memory overflow. I will share with you a program for processing network images that I saw on github.
The following is an example:
Take an image in jijie.com (www. jijie. cc) as an example. The source image is:
This shows the same image in different sizes. The Code just cut the image to avoid stretching and deformation, the asynchronous acquisition and automatic cache of programs will not be displayed. You can just read the code.
Engineering files (Baidu Network Disk): http://pan.baidu.com/s/1mguh2qc
Github: https://github.com/yimengqingqiu/Android-Universal-Image-Loader
Personal email: standopen@foxmail.com (you can also send me an email)