2

Given a bitmap i want to turn it to GrayScale. I found this solution but now that my phone got updated in Android 10 i get an IllegalArgumentException: Software rendering doesn't support hardware bitmaps exception.

fun getGrayScale(src: Bitmap): Bitmap {

        //Custom color matrix to convert to GrayScale
        val matrix = floatArrayOf(
            0.3f,
            0.59f,
            0.11f,
            0f,
            0f,
            0.3f,
            0.59f,
            0.11f,
            0f,
            0f,
            0.3f,
            0.59f,
            0.11f,
            0f,
            0f,
            0f,
            0f,
            0f,
            1f,
            0f
        )

        val dest = Bitmap.createBitmap(src.width, src.height, Bitmap.Config.RGB_565)

        val canvas = Canvas(dest)
        val paint = Paint()
        val filter = ColorMatrixColorFilter(matrix)
        paint.colorFilter = filter
        canvas.drawBitmap(src, 0.toFloat(), 0.toFloat(), paint)

        return dest
    }

So now i have 2 questions.
1) What should i change so that can work again
2) Can i do this with Glide libray so i dont need to write any code?

james04
  • 1,580
  • 2
  • 20
  • 46

0 Answers0