canvas.drawBitmap - Software rendering doesn't support hardware bitmaps

Viewed 1349

simple fun

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 API 29. Emulator API 28. Kotlin 1.3.40. About month ago this fun worked. But now on "canvas.drawBitmap" error "Software rendering doesn't support hardware bitmaps". Try android:hardwareAccelerated="false" - same error. Why?

1 Answers

so, my solution:

fun getCircleBitmapDrawable(bitmap: Bitmap): RoundedBitmapDrawable {
        val round = RoundedBitmapDrawableFactory.create(context.resources, bitmap)
        round.isCircular = true
        round.setAntiAlias(true)

        return round
    }
Related