Java Code Examples for com.bumptech.glide.GlideBuilder#setDecodeFormat()

The following examples show how to use com.bumptech.glide.GlideBuilder#setDecodeFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XGlideModule.java    From XKnife-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {

    //设置图片解码格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    //设置内存缓存大小
    int maxMemory = (int) Runtime.getRuntime().maxMemory();//获取系统分配给应用的总内存大小
    int memoryCacheSize = maxMemory / 8;//设置图片内存缓存占用八分之一
    builder.setMemoryCache(new LruResourceCache(memoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(memoryCacheSize));

    // 存放路径和缓存控件大小
    int diskCacheSize = 1024 * 1024 * 30;
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheName, diskCacheSize));  // data/data/xx/cache/
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, diskCacheName, diskCacheSize));  //存放在外置文件浏览器
}
 
Example 2
Source File: GlideModelConfig.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ) {
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }else {
        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
    }//解决rgb565部分手机上出现绿色问题
    //比较耗时,所以反向设置
   /* builder.setDiskCache(new DiskLruCacheFactory(new File(context.getCacheDir(), GlobalConfig.cacheFolderName).getAbsolutePath(),
            GlobalConfig.cacheMaxSize*1024*1024));*/
    Log.i("glide","applyOptions---");

   /* builder.setResizeService(new FifoPriorityThreadPoolExecutor(4))
            .setDiskCacheService(new FifoPriorityThreadPoolExecutor(4));*/

}
 
Example 3
Source File: GlideConfiguration.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);// Bitmap格式转换到ARGB_8888
    //内存缓存
    MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = memorySizeCalculator.getMemoryCacheSize();
    int defalutBitmapPoolSize = memorySizeCalculator.getBitmapPoolSize();
    builder.setMemoryCache(new LruResourceCache((int) (defalutBitmapPoolSize * 1.2)));//内部
    builder.setBitmapPool(new LruBitmapPool((int) (defalutBitmapPoolSize * 1.2)));
    //磁盘缓存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 1024 * 1024 * 10));//内部磁盘缓存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 10 * 1024 * 1024));//磁盘缓存到外部存储
    //指定缓存目录1
    String downLoadPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(new DiskLruCacheFactory(downLoadPath, defaultMemoryCacheSize));
    //指定缓存目录2
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File cacheLocation = new File(FileUtils.getCacheDir(context), "GlideCache");
            return DiskLruCacheWrapper.get(cacheLocation, 1024 * 1024 * 10);
        }
    });

}
 
Example 4
Source File: OkHttpProgressGlideModule.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    File cacheDir = new File(context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR);
    cache = DiskLruCacheWrapper.get(cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            return cache;
        }
    });
}
 
Example 5
Source File: GlideConfiguration.java    From RxPalette with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Prefer RGB 535 on lower end devices
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    builder.setDecodeFormat(ActivityManagerCompat.isLowRamDevice(am)
            ? DecodeFormat.PREFER_RGB_565
            : DecodeFormat.PREFER_ARGB_8888);
}
 
Example 6
Source File: GlideSetup.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //builder.setMemoryCache(new LruResourceCache(64 * 1024 * 1024));
    //builder.setBitmapPool(new LruBitmapPool(32 * 1024 * 1024));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 2147483647));
    builder.setResizeService(new FifoPriorityThreadPoolExecutor(2));
}
 
Example 7
Source File: CustomCachingGlideModule.java    From android-tutorials-glide with MIT License 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    // memory cache
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    // disk cache
    // set size & external vs. internal
    int cacheSize100MegaBytes = 104857600;

    builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));

    builder.setDiskCache(
            new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));

    // set custom location
    String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath();

    builder.setDiskCache(
            new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes));

    // In case you want to specify a cache folder ("glide"):
    //builder.setDiskCache(
    //        new DiskLruCacheFactory( downloadDirectoryPath, "glidecache", cacheSize100MegaBytes ) );

}
 
Example 8
Source File: GlideConfiguration.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Prefer higher quality images unless we're on a low RAM device
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    builder.setDecodeFormat(activityManager.isLowRamDevice() ?
                    DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
}
 
Example 9
Source File: OkHttpGlideModule.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
@Override
  public void applyOptions(Context context, GlideBuilder builder) {

//    int deskacheize = 1024 * 1024 * 30;
    int maxMemory = (int)Runtime.getRuntime().maxMemory();
    int memoryCheSize = maxMemory / 8;
//    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", deskacheize));
    builder.setDiskCache(new DiskLruCacheFactory(FileUtil.getCacheDir(),"glide", DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    builder.setMemoryCache(new LruResourceCache(memoryCheSize));
    builder.setBitmapPool(new LruBitmapPool(memoryCheSize));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
  }
 
Example 10
Source File: GlideConfigModule.java    From ImageLoadPK with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 指定位置在packageName/cache/glide_cache,大小为MAX_CACHE_DISK_SIZE的磁盘缓存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide_cache", ConfigConstants.MAX_CACHE_DISK_SIZE));
    //指定内存缓存大小
    builder.setMemoryCache(new LruResourceCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
    //全部的内存缓存用来作为图片缓存
    builder.setBitmapPool(new LruBitmapPool(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);//和Picasso配置一样
}
 
Example 11
Source File: OkHttpGlideModule.java    From AndroidModulePattern with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
 
Example 12
Source File: GlideModelConfig.java    From Android with MIT License 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Define cache size and location
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskSize));  //Mobile disk
    //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", diskSize)); //sdcard disk

    // The custom memory pool size and pictures
    builder.setMemoryCache(new LruResourceCache(memorySize));
    builder.setBitmapPool(new LruBitmapPool(memorySize));

    // Define the image format
    //builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
}
 
Example 13
Source File: OkHttpGlideModule.java    From TestChat with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
 
Example 14
Source File: GlideConfiguration.java    From Cirrus_depricated with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Apply options to the builder here.
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
 
Example 15
Source File: GlideConfigModule.java    From ImageLoadPK with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);//和Picasso配置一样
}
 
Example 16
Source File: SimpleGlideModule.java    From Android-Tech with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder glideBuilder) {
    // todo
    glideBuilder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
 
Example 17
Source File: ExampleGlideModule.java    From RecyclerAdapterBase with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
	builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
 
Example 18
Source File: SimpleGlideModule.java    From android-tutorials-glide with MIT License 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
 
Example 19
Source File: GlideConfiguration.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //如果你对默认的RGB_565效果还比较满意,可以不做任何事,但是如果你觉得难以接受,可以创建一个新的GlideModule将Bitmap格式转换到ARGB_8888:
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
}
 
Example 20
Source File: GlideConfiguration.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Set Glide decode format to the higher quality ARGB_8888 format
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}