简单有趣
fun getCircleBitmap(bitmap: Bitmap, recycle: Boolean): Bitmap {
val paint = Paint()
paint.isAntiAlias = true
paint.color = Color.WHITE
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
val rect = Rect(0, 0, bitmap.width, bitmap.height)
val rectF = RectF(rect)
val output = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
canvas.drawARGB(0, 0, 0, 0)
canvas.drawOval(rectF, paint)
canvas.drawBitmap(bitmap, rect, rect, paint)
if (recycle) {
bitmap.recycle()
}
return output
}
Taget API29。仿真器API28。Kotlin1.3.40。 大约一个月前,这种乐趣奏效了。但是现在出现在“ canvas.drawBitmap”错误“软件渲染不支持硬件位图”。尝试android:hardwareAccelerated =“ false”-相同的错误。为什么?
答案 0 :(得分:0)
所以,我的解决方法:
fun getCircleBitmapDrawable(bitmap: Bitmap): RoundedBitmapDrawable {
val round = RoundedBitmapDrawableFactory.create(context.resources, bitmap)
round.isCircular = true
round.setAntiAlias(true)
return round
}