Вот мой текущий код для извлечения окрашенной области:
Код: Выделить всё
fun getMaskedBitmap(originalBitmap: Bitmap): Bitmap {
val width = originalBitmap.width
val height = originalBitmap.height
// Create a new bitmap with transparency support
val maskedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(maskedBitmap)
// Fill the canvas with transparent color
canvas.drawColor(Color.TRANSPARENT)
// Draw the original image on the canvas
val imagePaint = Paint()
canvas.drawBitmap(originalBitmap, 0f, 0f, imagePaint)
// Create paint for the mask with DST_IN mode
val maskPaint = Paint().apply {
xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)
isAntiAlias = true
}
// Draw the path on the canvas to mask the region
canvas.drawPath(path, maskPaint)
return maskedBitmap
Подробнее здесь: https://stackoverflow.com/questions/790 ... in-android