ImageLoader, get pictures

// main Activity
public class MainActivity extends AppCompatActivity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView) findViewById(R.id.image);

    }

    public void imageLoad(View view){
        //使用imageloader加载图片

//        ImageLoader.getInstance().displayImage("http://p1.pstatp.com/list/39a80000a236833755b2",imageView);

        //ImageLoader.getInstance().displayImage("http://p3.pstatp.com/video1609/37ca0002fc54a831c948",imageView,ImageLoaderUtils.getDefautOption());

        ImageLoader.getInstance().displayImage("http://p3.pstatp.com/list/39a90000bbaa05b118eb",imageView,ImageLoaderUtils.getCircleOption());

    }
}
//ImageLoaderUtils 
public class ImageLoaderUtils {
     /**
      * Initialize imageloader configuration
 * @param context
 */
 public static void initConfiguration(Context context) {
        File cacheDir = StorageUtils.getCacheDirectory ( context);   // cache folder path
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder (context)
                .threadPoolSize( 3 ) // Generally 3,,,1-5
 .threadPriority(Thread.NORM_PRIORITY - 2 ) // default sets the priority of the current thread              

                        ,,, 1-10
                 .tasksProcessingOrder(QueueProcessingType.FIFO) // default
 .denyCacheImageMultipleSizesInMemory() // Refused to cache and load images with the same content but different sizes.memoryCache
 ( new LruMemoryCache( 2 * 1024 * 1024 )) // You can use your own Memory cache implementation.memoryCacheSize
 ( 2 * 1024 * 1024 )   // The maximum value of the memory
 cache.memoryCacheSizePercentage( 13 ) // default
 .diskCache( new UnlimitedDiskCache(cacheDir)) // The default can customize the cache path.diskCacheSize
 (                                                                                                50 * 1024 * 1024 ) // The maximum value of
 50 Mb sd card ( local ) cache.diskCacheFileCount( 100 )   // The number of files that can be cached
 // The default is to use HASHCODE to encrypt the name of UIL , you can also use MD5(new Md5FileNameGenerator ()) encryption.diskCacheFileNameGenerator
 ( new HashCodeFileNameGenerator()) 
                .imageDownloader( new BaseImageDownloader(context)) // default
 .imageDecoder( new BaseImageDecoder( true )) // default
                                                                                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs() // 打印debug log
                .build(); //开始构建

        //初始化
        ImageLoader.getInstance().init(config);
    }

    public static DisplayImageOptions getDefautOption() {

        DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher)
                .showImageOnLoading(R.mipmap.ic_launcher )
                .cacheInMemory( true )
                .cacheOnDisk( true )
                .imageScaleType( ImageScaleType.EXACTLY_STRETCHED )
                .resetViewBeforeLoading( true ) // Reset the display before loading.bitmapConfig
                 (Bitmap.Config.RGB_565 ) // Image quality.considerExifParams
                 ( true ) /// Whether to consider JPEG image EXIF ​​parameters (rotation, flip)
                 .build();
         return imageOptions;
    } /**
      * Circular image configuration


         * @return
     */
    public static DisplayImageOptions getCircleOption() {
        DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher)
                .showImageOnLoading(R.mipmap.ic_launcher)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                .resetViewBeforeLoading(true ) // Reset the display before loading.bitmapConfig
                 (Bitmap.Config.RGB_565) // The quality of the
 picture.considerExifParams( true ) /// Whether to consider JPEG image EXIF ​​parameters (rotation, flipping)
 .displayer ( new CircleBitmapDisplayer() ) // circular display.build
 ();
         return imageOptions;
    } /**
      * load rounded corner image
 * @return
 */
 public static DisplayImageOptions getBoundOption() {
        DisplayImageOptions imageOptions = new                                
                

                   DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.mipmap.ic_launcher ) 
                .showImageOnFail(R.mipmap.ic_launcher ) .showImageOnLoading ( 
                R.mipmap.ic_launcher ) .cacheInMemory 
                ( true ) 
                .cacheOnDisk( true ) 
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED ) .resetViewBeforeLoading 
                ( true ) / / Reset the display before loading.bitmapConfig
 (Bitmap.Config.RGB_565 ) // The quality of the
 picture.considerExifParams ( true ) ///                                Whether to consider JPEG image EXIF ​​parameters (rotation, flipping)
 .displayer( new RoundedBitmapDisplayer( 20 )) // Specify the size of the loaded rounded corners.build
 ();
         return imageOptions;
    }
}
                
                
//ImageApplication
public class ImageApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        ImageLoaderUtils.initConfigration(this);
    }
}
//BaseApplication
public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        //进行imageLoader的默认配置...上下文
        ImageLoaderConfiguration configuration = ImageLoaderConfiguration.createDefault(this);
        //初始化一下imageloader
        ImageLoader.getInstance().init(configuration);
    }
}

Guess you like

Origin blog.csdn.net/qq_40071033/article/details/77898410