From 3bf72b47e3cbaa2568290d9d2ab9f8fb45ea7854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 21 Nov 2024 12:49:42 +0900 Subject: [PATCH] fix(android): getCircleBitmap not displaying image --- .../com/adobe/phonegap/push/FCMService.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.kt b/src/android/com/adobe/phonegap/push/FCMService.kt index 2f0677488..1b2eb5979 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.kt +++ b/src/android/com/adobe/phonegap/push/FCMService.kt @@ -1012,23 +1012,25 @@ class FCMService : FirebaseMessagingService() { Bitmap.Config.ARGB_8888 ) + val canvas = Canvas(output) + canvas.drawARGB(0, 0, 0, 0) + val paint = Paint().apply { isAntiAlias = true color = Color.RED - xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) } - Canvas(output).apply { - drawARGB(0, 0, 0, 0) + val cx = (bitmap.width / 2).toFloat() + val cy = (bitmap.height / 2).toFloat() + val radius = minOf(cx, cy) - val cx = (bitmap.width / 2).toFloat() - val cy = (bitmap.height / 2).toFloat() - val radius = if (cx < cy) cx else cy - val rect = Rect(0, 0, bitmap.width, bitmap.height) + canvas.drawCircle(cx, cy, radius, paint) - drawCircle(cx, cy, radius, paint) - drawBitmap(bitmap, rect, rect, paint) - } + // Set the Xfermode to SRC_IN after drawing the circle, + // so that the bitmap will clip correctly inside the circle. + paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) + + canvas.drawBitmap(bitmap, 0f, 0f, paint) bitmap.recycle() return output