Created
September 23, 2018 12:25
-
-
Save fievx/3cfe2a5c82de8b33c5fab43dda485b06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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