com.bumptech.glide.load.DecodeFormat Java Examples
The following examples show how to use
com.bumptech.glide.load.DecodeFormat.
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: MyGlideModule.java From hipda with GNU General Public License v2.0 | 6 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder gb) { String cacheSizeStr = HiSettingsHelper.getInstance().getStringValue(HiSettingsHelper.PERF_CACHE_SIZE_IN_MB, DEFAULT_CACHE_SIZE + ""); int cacheSize = DEFAULT_CACHE_SIZE; if (TextUtils.isDigitsOnly(cacheSizeStr)) { cacheSize = Integer.parseInt(cacheSizeStr); if (cacheSize < MIN_CACHE_SIZE) { cacheSize = DEFAULT_CACHE_SIZE; } } gb.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, cacheSize * 1024 * 1024)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) gb.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); GlideHelper.initDefaultFiles(); }
Example #2
Source File: GlideConfiguration.java From GankGirl with GNU Lesser General Public License v2.1 | 6 votes |
@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 #3
Source File: GlideModelConfig.java From ImageLoader with Apache License 2.0 | 6 votes |
@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 #4
Source File: GalleryAdapter.java From MoeGallery with GNU General Public License v3.0 | 6 votes |
void bind(int position) { mPosition = position; mImage = mImageDataSource.get(position); if (mImage.getFileUrl() != null && Utils.isGif(mImage.getFileUrl())) { gifTag.setVisibility(VISIBLE); } else { gifTag.setVisibility(GONE); } mRequestManager.load(mImage.getPreviewUrl()) .asBitmap() .format(DecodeFormat.PREFER_RGB_565) .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.color.gray_overlay) .fitCenter().centerCrop().into(imageView); }
Example #5
Source File: BitmapPreFiller.java From giffun with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public void preFill(PreFillType.Builder... bitmapAttributeBuilders) { if (current != null) { current.cancel(); } PreFillType[] bitmapAttributes = new PreFillType[bitmapAttributeBuilders.length]; for (int i = 0; i < bitmapAttributeBuilders.length; i++) { PreFillType.Builder builder = bitmapAttributeBuilders[i]; if (builder.getConfig() == null) { builder.setConfig( defaultFormat == DecodeFormat.ALWAYS_ARGB_8888 || defaultFormat == DecodeFormat.PREFER_ARGB_8888 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); } bitmapAttributes[i] = builder.build(); } PreFillQueue allocationOrder = generateAllocationOrder(bitmapAttributes); current = new BitmapPreFillRunner(bitmapPool, memoryCache, allocationOrder); handler.post(current); }
Example #6
Source File: SvgBitmapDrawableTranscoder.java From SvgGlidePlugins with Apache License 2.0 | 6 votes |
@NonNull private Bitmap.Config getDecodeFormat(@Nullable Options options) { DecodeFormat decodeFormat = options == null ? null : options.get(GifOptions.DECODE_FORMAT); if (decodeFormat == null) { return Bitmap.Config.ARGB_8888; } switch (decodeFormat) { case PREFER_RGB_565: return Bitmap.Config.RGB_565; case PREFER_ARGB_8888: default: return Bitmap.Config.ARGB_8888; } }
Example #7
Source File: TestFragment_Separate.java From glide-support with The Unlicense | 6 votes |
@Override public void onAttach(Context context) { super.onAttach(context); paletteLoad = Glide .with(this) .using(new StreamUriLoader(context), InputStream.class) .from(Uri.class) .as(Palette.class) .diskCacheStrategy(DiskCacheStrategy.ALL) .encoder(new PaletteCacheEncoder(new PaletteEncoder())) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>( new PaletteCacheDecoder(new PaletteDecoder(), new StreamBitmapDecoder( Downsampler.AT_MOST, Glide.get(context).getBitmapPool(), DecodeFormat.DEFAULT)))) .override(256, 256) // rough size of the Bitmap to generate Palette from .dontTransform() // default, but be explicit .dontAnimate() // default, but be explicit .skipMemoryCache(true) // debug to always go for disk ; }
Example #8
Source File: BitmapUtil.java From Silence with GNU General Public License v3.0 | 6 votes |
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height) throws BitmapDecodingException { final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model), Glide.get(context).getBitmapPool(), width, height, DecodeFormat.PREFER_RGB_565); final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool()); final Resource<Bitmap> result = new FitCenter(context).transform(resource, width, height); if (result == null) { throw new BitmapDecodingException("unable to transform Bitmap"); } return result.get(); }
Example #9
Source File: VideoBitmapDecoder.java From giffun with Apache License 2.0 | 6 votes |
@Override public Bitmap decode(ParcelFileDescriptor resource, BitmapPool bitmapPool, int outWidth, int outHeight, DecodeFormat decodeFormat) throws IOException { MediaMetadataRetriever mediaMetadataRetriever = factory.build(); mediaMetadataRetriever.setDataSource(resource.getFileDescriptor()); Bitmap result; if (frame >= 0) { result = mediaMetadataRetriever.getFrameAtTime(frame); } else { result = mediaMetadataRetriever.getFrameAtTime(); } mediaMetadataRetriever.release(); resource.close(); return result; }
Example #10
Source File: XGlideModule.java From XKnife-Android with Apache License 2.0 | 6 votes |
@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 #11
Source File: GlideModifications.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(RequestOptions.formatOf(DecodeFormat.PREFER_RGB_565)); // disk cache config //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); // using defaults MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build(); // size for memory cache int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // size for bitmap pool int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize)); }
Example #12
Source File: TestFragment.java From glide-support with The Unlicense | 6 votes |
@Override protected void load(Context context) throws Exception { String url = "http://www.online-image-editor.com//styles/2014/images/example_image.png"; String url2 = "http://a5.mzstatic.com/us/r30/Purple5/v4/5a/2e/e9/5a2ee9b3-8f0e-4f8b-4043-dd3e3ea29766/icon128-2x.png"; BitmapRequestBuilder<String, Bitmap> request = Glide .with(context) .load(url) .asBitmap() .format(DecodeFormat.PREFER_ARGB_8888) .thumbnail(Glide .with(context) .load(url2) .asBitmap() ); loadProper(request); loadHacky(request); loadHackyAlt(request); }
Example #13
Source File: TestFragment_Inclusive.java From glide-support with The Unlicense | 6 votes |
@Override public void onAttach(Context context) { super.onAttach(context); BitmapPool pool = Glide.get(context).getBitmapPool(); StreamBitmapDecoder bitmapDecoder = new StreamBitmapDecoder(Downsampler.AT_LEAST, pool, DecodeFormat.DEFAULT); paletteLoad = Glide .with(this) .using(new StreamUriLoader(context), InputStream.class) .from(Uri.class) .as(PaletteBitmap.class) .diskCacheStrategy(DiskCacheStrategy.ALL) .encoder(new PaletteBitmapEncoder(new BitmapEncoder(), new PaletteEncoder())) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>( new PaletteBitmapDecoder(pool, bitmapDecoder, new PaletteDecoder()))) .dontAnimate() .skipMemoryCache(true) // debug to always go for disk ; }
Example #14
Source File: MyAppGlideModule.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); int memoryCacheSizeBytes = 1024 * 1024 * 20; builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes)); int bitmapPoolSizeBytes = 1024 * 1024 * 30; builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes)); int diskCacheSizeBytes = 1024 * 1024 * 100; builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); }
Example #15
Source File: ImageLoader.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@SuppressLint("CheckResult") @NonNull private RequestOptions getRequestOptions() { RequestOptions requestOptions = new RequestOptions(); DecodeFormat decodeFormat; if (Build.VERSION.SDK_INT >= 26) { decodeFormat = DecodeFormat.PREFER_ARGB_8888; requestOptions.disallowHardwareConfig(); } else { decodeFormat = DecodeFormat.PREFER_RGB_565; } return requestOptions.format(decodeFormat) .diskCacheStrategy(DiskCacheStrategy.RESOURCE); }
Example #16
Source File: GlideConfiguration.java From android-proguards with Apache License 2.0 | 5 votes |
@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 #17
Source File: AbstractGlideModule.java From Common with Apache License 2.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)) .setDiskCache(new ExternalCacheDiskCacheFactory(context, getCachePath(), 1024 * 1024 * 1024)) .setMemoryCache(new LruResourceCache(3 * 1024 * 1024)) .setBitmapPool(new LruBitmapPool(3 * 1024 * 1024)); }
Example #18
Source File: NewsDetailActivity.java From ZZShow with Apache License 2.0 | 5 votes |
@Override public void initViews() { toolbarLayout.setExpandedTitleColor(ContextCompat.getColor(this, R.color.title_color)); toolbarLayout.setCollapsedTitleTextColor(ContextCompat.getColor(this, R.color.title_color)); Glide.with(this).load(mPostImgPath).asBitmap() .placeholder(R.mipmap.ic_loading) .format(DecodeFormat.PREFER_ARGB_8888) .error(R.mipmap.ic_load_fail) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(newsDetailPictureIv); }
Example #19
Source File: CustomCachingGlideModule.java From android-tutorials-glide with MIT License | 5 votes |
@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 #20
Source File: TestFragment.java From glide-support with The Unlicense | 5 votes |
@Override protected void load(Context context) throws Exception { String url = "https://s3.amazonaws.com/timeset-photos/RackMultipart20151217-4907-vnn7er.jpeg"; url = "https://cloud.githubusercontent.com/assets/2364583/11941136/528db8a0-a7e2-11e5-9327-d6cc11548c91.JPG"; Glide .with(context) .load(url) .asBitmap() .format(DecodeFormat.PREFER_ARGB_8888) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(imageView); }
Example #21
Source File: CustomImgPickerPresenter.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) { Object object = item.getUri() != null ? item.getUri() : item.path; Glide.with(view.getContext()).load(object).apply(new RequestOptions() .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888)) .override(isThumbnail ? size : Target.SIZE_ORIGINAL) .into((ImageView) view); }
Example #22
Source File: RedBookPresenter.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) { Object object = item.getUri() != null ? item.getUri() : item.path; Glide.with(view.getContext()).load(object).apply(new RequestOptions() .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888)) .override(isThumbnail ? size : Target.SIZE_ORIGINAL) .into((ImageView) view); }
Example #23
Source File: CustomImgPickerPresenter.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) { Object object = item.getUri() != null ? item.getUri() : item.path; Glide.with(view.getContext()).load(object).apply(new RequestOptions() .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888)) .override(isThumbnail ? size : Target.SIZE_ORIGINAL) .into((ImageView) view); }
Example #24
Source File: RedBookPresenter.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) { Object object = item.getUri() != null ? item.getUri() : item.path; Glide.with(view.getContext()).load(object).apply(new RequestOptions() .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888)) .override(isThumbnail ? size : Target.SIZE_ORIGINAL) .into((ImageView) view); }
Example #25
Source File: OkHttpGlideModule.java From AndroidModulePattern with Apache License 2.0 | 5 votes |
@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 #26
Source File: GlideConfig.java From MVVM-JueJin with MIT License | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder // 下面三项都是默认的, 不必设置 // .setMemoryCache(new LruResourceCache(MEMORY_CACHE_SIZE)) // .setBitmapPool(new LruBitmapPool(MEMORY_CACHE_SIZE)) // 默认 rgb565 .setDecodeFormat(DecodeFormat.PREFER_ARGB_8888) .setDiskCache(new InternalCacheDiskCacheFactory(context, DISK_CACHE_SIZE)); }
Example #27
Source File: AbstractGlideModule.java From DMusic with Apache License 2.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)) .setDiskCache(new ExternalCacheDiskCacheFactory(context, getCachePath(), 1024 * 1024 * 1024)) .setMemoryCache(new LruResourceCache(3 * 1024 * 1024)) .setBitmapPool(new LruBitmapPool(3 * 1024 * 1024)); }
Example #28
Source File: OkHttpGlideModule.java From TestChat with Apache License 2.0 | 5 votes |
@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 #29
Source File: Glide4Loader.java From ImageLoader with Apache License 2.0 | 5 votes |
private RequestOptions buildOptions(SingleConfig config) { RequestOptions options = new RequestOptions() .format(DecodeFormat.PREFER_RGB_565) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .skipMemoryCache(GlobalConfig.debug) .transform(getBitmapTransFormations(config)); return options; }
Example #30
Source File: GlideModelConfig.java From Android with MIT License | 5 votes |
@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); }