Skip to content

Instantly share code, notes, and snippets.

@s3va
Created November 26, 2024 10:54
Show Gist options
  • Save s3va/7081adf0771a0e8e609ec97e64a23f88 to your computer and use it in GitHub Desktop.
Save s3va/7081adf0771a0e8e609ec97e64a23f88 to your computer and use it in GitHub Desktop.
Crate Bitmap With Circle In It
// https://stackoverflow.com/a/68228461/11798617
private fun drawCircle300(): Bitmap? {
var radius = 150f
val bitmap = Bitmap.createBitmap(
(radius * 2).toInt(),
(radius * 2).toInt(),
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
val paint = Paint().apply {
strokeWidth = 3f
style = Paint.Style.FILL
isAntiAlias = true
}
val rect = RectF(0f, 0f, 300f, 300f)
var degree = 72f
var currentAngle = 0f
for (i in 0 until 5) {
if (i == 0)
paint.color = Color.BLACK
if (i == 1)
paint.color = Color.BLUE
if (i == 2)
paint.color = Color.RED
if (i == 3)
paint.color = Color.YELLOW
if (i == 4)
paint.color = Color.GREEN
canvas.drawArc(rect, currentAngle, degree, true, paint)
currentAngle += degree
}
return bitmap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment