I know there are lots of link available to make ImageView
Round Corner.
But I\'m Using Picasso
Library for Image Loading..
I refer the link to get
Kotlin version of RoundCornerTransform based on @stevyhacker 's answer.
=============================================
import android.graphics.*
import com.squareup.picasso.Transformation
class RoundCornersTransform(private val radiusInPx: Float) : Transformation {
override fun transform(source: Bitmap): Bitmap {
val bitmap = Bitmap.createBitmap(source.width, source.height, source.config)
val canvas = Canvas(bitmap)
val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)
val shader = BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
paint.shader = shader
val rect = RectF(0.0f, 0.0f, source.width.toFloat(), source.height.toFloat())
canvas.drawRoundRect(rect, radiusInPx, radiusInPx, paint)
source.recycle()
return bitmap
}
override fun key(): String {
return "round_corners"
}
}
Usage:
Picasso.get()
.load(imageUrl)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.placeholder(R.drawable.image_placeholder)
.transform(RoundCornersTransform(32.0f))
.into(imageView, callback)