Skip to content

Instantly share code, notes, and snippets.

@frel
Created August 15, 2021 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frel/ca85e79cacd11b8a5a6ae6ec194c18c4 to your computer and use it in GitHub Desktop.
Save frel/ca85e79cacd11b8a5a6ae6ec194c18c4 to your computer and use it in GitHub Desktop.
AirBrush Medium article example
@GlideModule
class GlideModule : AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
// Register a ModelLoaderFactory for TinyThumb allowing the type to be loaded using Glide
registry.append(TinyThumb::class.java, TinyThumb::class.java, TinyThumbLoader.Factory())
// Register a ResourceDecoder for TinyThumb. Specifying the input and output type.
// Note that the tailing lambda is the blur provider. If we wanted to use another blur
// implementation we could replace it here.
registry.append(
TinyThumb::class.java,
BitmapDrawable::class.java,
TinyThumbDecoder(context, glide.bitmapPool) { bitmap, options ->
// The options parameter is an optional override, allowing per request blur values
// such as radius and sample size. The default radius depends on your use case(s).
val radius = options?.radius ?: 15f
AirBrush.blur(context, bitmap, scale = 1f, radius = radius)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment