Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CircleCropTransformation : Transformation {
- override fun transform(source: Bitmap?): Bitmap {
- val size: Int = Math.min(source!!.width, source.height)
- val x: Int = (source.width - size) / 2
- val y: Int = (source.height - size) / 2
- val squaredBitmap: Bitmap = Bitmap.createBitmap(source, x, y, size, size)
- if (squaredBitmap != source) {
- source.recycle()
- }
- val bitmap: Bitmap = Bitmap.createBitmap(size, size, source.config)
- val canvas = Canvas(bitmap)
- val paint = Paint()
- val shader = BitmapShader(
- squaredBitmap,
- Shader.TileMode.CLAMP,
- Shader.TileMode.CLAMP
- )
- paint.shader = shader
- paint.isAntiAlias = true
- val r = size / 2f
- canvas.drawCircle(r, r, r, paint)
- squaredBitmap.recycle()
- return bitmap
- }
- override fun key(): String {
- return "circle"
- }
- }
Add Comment
Please, Sign In to add comment