이것은 현재 Picasso 3 스냅 샷과 함께 작동합니다.
class CircleTransformation : Transformation {
override fun transform(source: RequestHandler.Result): RequestHandler.Result {
if (source.bitmap == null) {
return source
}
var bitmap: Bitmap
// since we cant transform hardware bitmaps create a software copy first
if (VERSION.SDK_INT >= VERSION_CODES.O && source.bitmap!!.config == Config.HARDWARE) {
val softwareCopy = source.bitmap!!.copy(Config.ARGB_8888, true)
if (softwareCopy == null) {
return source
} else {
bitmap = softwareCopy
source.bitmap!!.recycle()
}
} else {
bitmap = source.bitmap!!
}
var size = bitmap.width
// if bitmap is non-square first create square one
if (size != bitmap.height) {
var sizeX = size
var sizeY = bitmap.height
size = Math.min(sizeY, sizeX)
sizeX = (sizeX - size) / 2
sizeY = (sizeY - size) / 2
val squareSource = Bitmap.createBitmap(bitmap, sizeX, sizeY, size, size)
bitmap.recycle()
bitmap = squareSource
}
val circleBitmap = Bitmap.createBitmap(size, size, Config.ARGB_8888)
val canvas = Canvas(circleBitmap)
val paint = Paint()
val shader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
paint.shader = shader
paint.isAntiAlias = true
val centerAndRadius = size / 2f
canvas.drawCircle(centerAndRadius, centerAndRadius, centerAndRadius, paint)
bitmap.recycle()
return RequestHandler.Result(circleBitmap, source.loadedFrom, source.exifRotation)
}
override fun key(): String {
return "circleTransformation()"
}
}
Picasso3 요점 : https://gist.github.com/G00fY2/f3fbc468570024930c1fd9eb4cec85a1