Skip to content

Instantly share code, notes, and snippets.

@fievx
Created September 23, 2018 12:25
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 fievx/3cfe2a5c82de8b33c5fab43dda485b06 to your computer and use it in GitHub Desktop.
Save fievx/3cfe2a5c82de8b33c5fab43dda485b06 to your computer and use it in GitHub Desktop.
private var shadow: Bitmap? = null
private val shadowPaint = Paint(ANTI_ALIAS_FLAG)
private var shadowRadius = context.resources.getDimension(R.dimen.shadow_default_radius)
private var shadowXOffset = context.resources.getDimension(R.dimen.shadow_default_x_translation)
private var shadowYOffset = context.resources.getDimension(R.dimen.shadow_default_y_translation)
private var shadowColor = ContextCompat.getColor(context, R.color.shadow_default_color)
private lateinit var shadowView: ImageView
private fun generateShadow() {
shadow = Bitmap.createBitmap(shadowView.width, shadowView.height, Bitmap.Config.ALPHA_8)
shadowPaint.apply {
colorFilter = PorterDuffColorFilter(shadowColor, PorterDuff.Mode.SRC_IN)
setShadowLayer(shadowRadius, shadowXOffset, shadowYOffset, shadowColor)
}
val c = Canvas(shadow)
shadowPath.let { path->
c.drawPath(path, shadowPaint)
shadowView.setImageBitmap(shadow)
isShadowDirty = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment