ImageLoader、画像を取得

//主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());
イメージローダー。getInstance ( ).displayImage( "http://p3.pstatp.com/list/39a90000bbaa05b118eb" , imageView ,ImageLoaderUtils.getCircleOption()); 
    }
}
        
// ImageLoaderUtils
public class ImageLoaderUtils {
     /**
      * imageloader構成
の初期化* @param context
 */
 public static void initConfiguration(Context context) {
        File cacheDir = StorageUtils.getCacheDirectory ( context);   //キャッシュ フォルダー パス
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder (context )
                .threadPoolSize( 3 ) //通常は3,,,1-5
 .threadPriority(Thread.NORM_PRIORITY - 2 ) //デフォルトでは現在のスレッドの優先度が設定されます              

                        ,,, 1-10
                 .tasksProcessingOrder(QueueProcessingType.FIFO) // default
 .denyCacheImageMultipleSizesInMemory() //内容は同じでもサイズが異なる画像のキャッシュとロードを拒否.memoryCache
 ( new LruMemoryCache( 2 * 1024 * 1024 )) //独自のメモリ キャッシュを使用できます implementation.memoryCacheSize
 ( 2 * 1024 * 1024 )   //メモリの最大値
cache.memoryCacheSizePercentage( 13 ) // デフォルト
.diskCache( new UnlimitedDiskCache(cacheDir)) // デフォルトでは、キャッシュパス.diskCacheSize
 (                                                                                                50 * 1024 * 1024 ) // 50 Mb sdカードの最大値
(ローカル) cache.diskCacheFileCount( 100 )   //キャッシュできるファイルの数
// デフォルトではHASHCODEを使用してUILの名前を暗号化しますMD5(new Md5FileNameGenerator ()) encryption.diskCacheFileNameGenerator
 ( new HashCodeFileNameGenerator()) 
                .imageDownloader( new BaseImageDownloader(context)) // デフォルト
.imageDecoder( new BaseImageDecoder( true )) // デフォルト
も使用できます                                                                                .defaultDisplayImageOptions(DisplayImageOptions. createSimple ()) // デフォルト
                .writeDebugLogs() //デバッグ ログ
を打刻.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 ) //読み込み前に表示をリセット.bitmapConfig
                 (Bitmap.Config.RGB_565 ) //画質.considerExifParams
                 ( true ) / // JPEG画像を考慮するかどうかEXIFパラメータ (回転、反転)
 .build();
         return imageOptions;
    } /**
      *循環画像の構成
                

         * @return
 */
 public static DisplayImageOptions getCircleOption() {
                DisplayImageOptions
        imageOptions = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.mipmap.ic_launcher ) .showImageOnFail
                ()
                .showImageOnLoading( R.mipmap.ic_launcher ) .cacheInMemory( true )
                .cacheOnDisk( true )
                .imageScaleType(ImageScaleType. EXACTLY_STRETCHED )
                .resetViewBeforeLoading(         true ) //読み込み前に表示をリセットします.bitmapConfig
                 (Bitmap.Config.RGB_565) //画像の品質
.considerExifParams( t​​rue ) /// JPEG画像のEXIFパラメータ(回転、反転)
を考慮するかどうか.displayer ( new CircleBitmapDisplayer() ) // circle display.build
 ();
         return imageOptions;
    } /**
      *角の丸い画像をロード
* @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 
                () 
                .cacheOnDisk() 
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED ) .resetViewBeforeLoading 
                () / /読み込み前に表示をリセット.bitmapConfig
 (Bitmap.Config.RGB_565 ) //画像の品質
.considerExifParams ( true ) ///                                JPEG画像を考慮するかどうかEXIFパラメータ (回転、反転)
 .displayer( new RoundedBitmapDisplayer( 20 )) //読み込まれた角丸のサイズを指定します.build
 ();
         return imageOptions;
    }
}
                
                
// ImageApplication
public class ImageApplication extends Application { @Override
 public void onCreate() {
         super .onCreate(); 
        ImageLoaderUtils. initConfigration (これ); 
    }
}

        

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

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

おすすめ

転載: blog.csdn.net/qq_40071033/article/details/77898410