Image-loader image loading framework to download images and custom paths

【tips】:

The last lesson talked about how to configure the Universal-Image-Loader framework foolishly. Now let's discuss how to define the image download path name and format. Here we will discuss it, then the Universal-Image-Loader framework is cached by default. What the picture will look like.

First we found our package in the memory card: ImageLoader

The above are the pictures that have been used for the experiment several times. However, if you look closely, it is actually very different from the pictures:

Let's take a look

==================================================================================

Case 1

It is cached by default. In this case, no processing is required. The downloaded file is in the default file format and the name is also the default. The image size is smaller than the original.




 

This is the downloaded picture, and you have to choose it when watching it. But the advantage is that it has basically been cropped, and the display is relatively small.

==================================================================================

 

Case two:

 

Custom cache location image name and format

 

<!--EndFragment-->

public void loadimage(View v){
		final ImageView mImageView = (ImageView) findViewById(R.id.image);  
        String imageUrl="http://p4.so.qhmsg.com/sdr/1228_768_/t01a44e436353c96159.jpg";       
 // ImageLoader.getInstance().displayImage(imageUrl, mImageView); // imageUrl represents the URL address of the image, and imageView represents the IMAGEVIEW control that carries the image  
        ImageSize mImageSize = new ImageSize(500, 800);  
          
        // display image configuration  
        DisplayImageOptions options;  
        options = new DisplayImageOptions.Builder()  
         .showImageOnLoading(R.drawable.ic_launcher) //Set the image displayed during download  
         .showImageForEmptyUri(R.drawable.ic_launcher)//Set the image displayed when the image Uri is empty or wrong  
        .showImageOnFail(R.drawable.ic_launcher) //Set the image displayed when there is an error in the image loading/decoding process
        .cacheInMemory(true)//Set whether the downloaded image is cached in memory  
        .cacheOnDisc(true)//Set whether the downloaded pictures are cached in the SD card  
        .considerExifParams(true) //Whether to consider JPEG image EXIF ​​parameters (rotation, flip)
        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//Set how the picture is encoded  
        .bitmapConfig(Bitmap.Config.RGB_565)//Set the decoding type of the picture//  
        //.delayBeforeLoading(int delayInMillis)//int delayInMillis is the delay time before downloading that you set
        //Set the bitmap before adding the image to the cache  
        //.preProcessor(BitmapProcessor preProcessor)  
        .resetViewBeforeLoading(true)//Set whether the picture is reset before downloading, reset  
        .displayer(new RoundedBitmapDisplayer(80))//Whether it is set to rounded corners, what is the radian  
        .displayer(new FadeInBitmapDisplayer(100))//Whether the animation time of the fade-in after the image is loaded  
        .build();//build completed  
       
        for(i=0;i<imgname.length;i++){  
        imageload.loadImage(imgname[i], mImageSize, options, new SimpleImageLoadingListener(){  
  
            @Override  
            public void onLoadingComplete(String imageUri, View view,  
                    Bitmap loadedImage) {  
                super.onLoadingComplete(imageUri, view, loadedImage);  
                mImageView.setImageBitmap(loadedImage);
               
                /** preservation method*/
               
             
                File f=new File("/storage/emulated/0/imageloader/cache/"+i+".png");
                 if (f.exists()) {
                  f.delete();
                 }
                 try {
                  FileOutputStream out = new FileOutputStream(f);
                  loadedImage.compress(Bitmap.CompressFormat.PNG, 90, out);
                  out.flush();
                  out.close();
                  Log.i("TAG", "Saved");
                 } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace ();
                 } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace ();
                 }

                }
              
        });  
        }
}

 Changed the code from yesterday:
 

   public void onLoadingComplete(String imageUri, View view,  
                    Bitmap loadedImage)

 In this method, after the download is complete, it will give us a Bitmap image file, which is also used to display on the ImageView. Since the Bitmap has been obtained, it is very convenient and simple to save it locally, so that it can be solved perfectly By default, the name and format of the idiot are cached. Because every time you download an image, you need to provide a URL address, so for the purpose of class distinction, a class is specially created to store the URL.

 



 

public class ConfigField {
	
	public  static class ImageURL{
		public static final String yuelu[]=new String[]{"http://img.ivsky.com/img/tupian/img/201105/02/hunan_changsha_yuelushuyuan-013.jpg",
			"http://pic19.nipic.com/20120327/2885592_152659703164_2.jpg","http://img.ivsky.com/img/tupian/img/201105/02/hunan_changsha_yuelushuyuan-009.jpg"
			,"http://a3.att.hudong.com/03/86/20300000432220134079869338986.jpg",
			"http://img.ivsky.com/img/tupian/img/201105/02/hunan_changsha_yuelushuyuan-001.jpg"};
	
			
	}
	

}

 It can be seen from the above code that all URLs are stored in an array of String type and can be called directly by the class using the static modifier, which is more convenient. MainActivity builds an array of strings to receive this URL

 

 

  public String[] imgname=ConfigField.ImageURL.yuelu;

 Use a for loop to keep loading

 

After running like this, open the memory card of the mobile phone and see the situation:

 



 So far, it has been successful, and the above code still has some doubts, because the cut rounded image has not been successful. I will go back to study this and send it to the next class.

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

<!--EndFragment-->

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326612320&siteId=291194637