com.bumptech.glide.load.resource.file.FileToStreamDecoder Java Examples
The following examples show how to use
com.bumptech.glide.load.resource.file.FileToStreamDecoder.
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: 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 #2
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 #3
Source File: GeneratingAdapter.java From glide-support with The Unlicense | 6 votes |
public GeneratingAdapter(final Context context) { generator = Glide // this part should be cleaner in Glide 4.0, but that's not released yet .with(context) .using(new GeneratePassthroughModelLoader(), GenerateParams.class) // custom class .from(GenerateParams.class) .as(Bitmap.class) .transcode(new BitmapToGlideDrawableTranscoder(context), GlideDrawable.class) // builtin .decoder(new GenerateBitmapResourceDecoder(context)) // custom class .encoder(new BitmapEncoder(Bitmap.CompressFormat.PNG, 0/*ignored for lossless*/)) // builtin .cacheDecoder(new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(context))) // builtin //.placeholder(new ColorDrawable(Color.YELLOW)) // you can pre-set placeholder and error //.error(new ColorDrawable(Color.RED)) // so it's easier when binding //.diskCacheStrategy(DiskCacheStrategy.NONE) // only for debugging to always regenerate //.skipMemoryCache(true) // only for debugging to always regenerate ; }
Example #4
Source File: ImageZoomPresenter.java From incubator-taverna-mobile with Apache License 2.0 | 6 votes |
@Override public void attachView(ImageZoomMvpView mvpView) { super.attachView(mvpView); requestBuilder = Glide.with(getMvpView().getAppContext()) .using(Glide.buildStreamModelLoader(Uri.class, getMvpView().getAppContext()), InputStream.class) .from(Uri.class) .as(SVG.class) .transcode(new SvgDrawableTranscoder(), PictureDrawable.class) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<SVG>(new SvgDecoder())) .decoder(new SvgDecoder()) .placeholder(R.drawable.placeholder) .error(R.drawable.placeholder) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .animate(android.R.anim.fade_in); }
Example #5
Source File: ImageVideoGifDrawableLoadProvider.java From giffun with Apache License 2.0 | 5 votes |
public ImageVideoGifDrawableLoadProvider(DataLoadProvider<ImageVideoWrapper, Bitmap> bitmapProvider, DataLoadProvider<InputStream, GifDrawable> gifProvider, BitmapPool bitmapPool) { final GifBitmapWrapperResourceDecoder decoder = new GifBitmapWrapperResourceDecoder( bitmapProvider.getSourceDecoder(), gifProvider.getSourceDecoder(), bitmapPool ); cacheDecoder = new FileToStreamDecoder<GifBitmapWrapper>(new GifBitmapWrapperStreamResourceDecoder(decoder)); sourceDecoder = decoder; encoder = new GifBitmapWrapperResourceEncoder(bitmapProvider.getEncoder(), gifProvider.getEncoder()); //TODO: what about the gif provider? sourceEncoder = bitmapProvider.getSourceEncoder(); }
Example #6
Source File: TestFragment.java From glide-support with The Unlicense | 5 votes |
@SuppressWarnings("unchecked") @Override protected void load(Context context) { GenericRequestBuilder<Bitmap, Bitmap, Bitmap, Bitmap> glide = Glide .with(context) .using(new PassthroughModelLoader<Bitmap, Bitmap>(), Bitmap.class) .from(Bitmap.class) .as(Bitmap.class) .decoder(new BitmapBitmapResourceDecoder(context)) .cacheDecoder(new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(context))) .encoder(new BitmapEncoder()) // or .diskCacheStrategy(DiskCacheStrategy.NONE) instead of last 2 ; // simulate a bitmap input Drawable drawable = ContextCompat.getDrawable(context, android.R.drawable.sym_def_app_icon); Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); glide .clone() .load(bitmap) .signature(new StringSignature("android.R.drawable.sym_def_app_icon")) // required for caching .diskCacheStrategy(DiskCacheStrategy.NONE) // but can't really cache it, see #122 comments .transform(new CenterCrop(context)) .into(imageView) ; }
Example #7
Source File: TestFragment.java From glide-support with The Unlicense | 5 votes |
@Override protected void load(Context context) throws Exception { String model = "http://.../....dng"; //File model = ...; Glide .with(context) .load(model) .asBitmap() .imageDecoder(new RawStreamDecoder(context)) .encoder(new RawStreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new RawStreamDecoder(context))) .into(imageView) ; }
Example #8
Source File: MainModule.java From MoeGallery with GNU General Public License v3.0 | 5 votes |
@Singleton @Provides GenericRequestBuilder<GlideUrl, InputStream, byte[], GifDrawable> provideGifRequestBuilder( RequestManager requestManager, OkHttpClient okHttpClient) { return requestManager.using(new OkHttpUrlLoader(okHttpClient), InputStream.class) .from(GlideUrl.class) .as(byte[].class) .transcode(new GifDrawableBytesTranscoder(), GifDrawable.class) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .decoder(new StreamByteArrayResourceDecoder()) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new StreamByteArrayResourceDecoder())); }
Example #9
Source File: GifDrawableLoadProvider.java From giffun with Apache License 2.0 | 4 votes |
public GifDrawableLoadProvider(Context context, BitmapPool bitmapPool) { decoder = new GifResourceDecoder(context, bitmapPool); cacheDecoder = new FileToStreamDecoder<GifDrawable>(decoder); encoder = new GifResourceEncoder(bitmapPool); sourceEncoder = new StreamEncoder(); }
Example #10
Source File: StreamBitmapDataLoadProvider.java From giffun with Apache License 2.0 | 4 votes |
public StreamBitmapDataLoadProvider(BitmapPool bitmapPool, DecodeFormat decodeFormat) { sourceEncoder = new StreamEncoder(); decoder = new StreamBitmapDecoder(bitmapPool, decodeFormat); encoder = new BitmapEncoder(); cacheDecoder = new FileToStreamDecoder<Bitmap>(decoder); }
Example #11
Source File: FileDescriptorBitmapDataLoadProvider.java From giffun with Apache License 2.0 | 4 votes |
public FileDescriptorBitmapDataLoadProvider(BitmapPool bitmapPool, DecodeFormat decodeFormat) { cacheDecoder = new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(bitmapPool, decodeFormat)); sourceDecoder = new FileDescriptorBitmapDecoder(bitmapPool, decodeFormat); encoder = new BitmapEncoder(); sourceEncoder = NullEncoder.get(); }
Example #12
Source File: TestFragment.java From glide-support with The Unlicense | 4 votes |
@SuppressWarnings("unchecked") @Override public void onAttach(Context context) { super.onAttach(context); BitmapPool pool = Glide.get(context).getBitmapPool(); // default decoder, this is the base complexity Glide.with.load.into() hides from you GifBitmapWrapperStreamResourceDecoder decoder = new GifBitmapWrapperStreamResourceDecoder( new GifBitmapWrapperResourceDecoder( new ImageVideoBitmapDecoder( new StreamBitmapDecoder(pool), new FileDescriptorBitmapDecoder(context) ), new GifResourceDecoder(context, pool), pool ) ); // all the defaults hardcoded here in order to end up with a normal Drawable instead of a GlideDrawable urlGlide = Glide .with(this) .using(new StreamStringLoader(getActivity()), InputStream.class) .from(String.class) .as(GifBitmapWrapper.class) .transcode(new GeneralizingTranscoder<GifBitmapWrapper, GlideDrawable, Drawable>( new GifBitmapWrapperDrawableTranscoder(new GlideBitmapDrawableTranscoder(context))), Drawable.class) .decoder(decoder) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(decoder)) .animate(new AlwaysCrossFade<>(true)) .encoder(new GifBitmapWrapperResourceEncoder(new BitmapEncoder(), new GifResourceEncoder(pool))) .diskCacheStrategy(DiskCacheStrategy.ALL) // just to demonstrate it's working, pick your preference .transform(new GifBitmapWrapperTransformation(pool, new FitCenter(context))) // == .fitCenter() .listener(new LoggingListener<String, Drawable>("url")) // debug ; // see https://github.com/bumptech/glide/issues/122#issuecomment-99629392 drawableGlide = Glide .with(this) .using(new PassthroughModelLoader<Drawable, Drawable>(), Drawable.class) .from(Drawable.class) .as(Drawable.class) // this works even if the drawables don't behave well regarding constantState.newDrawable // Beware: might be problematic if constant state is supported, but altered (e.g. color filters) .decoder(new SimpleResourceDecoder<Drawable>()) // prefer DrawableResourceDecoder if possible! .animate(new AlwaysCrossFade<>(true)) .diskCacheStrategy(DiskCacheStrategy.NONE) .listener(new LoggingListener<Drawable, Drawable>("drawable")) // debug ; // prevents null check the first time // don't forge to null everything out explicitly (error/placeholder/fallback/thumbnail), if they're set above lastLoad = urlGlide.clone().load(null).listener(null).dontAnimate(); }