Skip to content

Commit

Permalink
fix(android): getCircleBitmap not displaying image
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Nov 21, 2024
1 parent 55733cd commit 3bf72b4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/android/com/adobe/phonegap/push/FCMService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bf72b4

Please sign in to comment.