Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- jsontokotlinclass
- 403 Error
- navigation component
- LOG
- ChromeCustomTab
- kdoc-generator
- Android
- datastore
- Git
- circlecrop
- onResume
- shotcut
- App Startup
- BottomSheetDialog
- room
- onReceivedSslError
- requestPermission
- ExifInterface
- itemAnimator
- Blinking
- notification bar
- notification setting
- application
- Plugins
- ActivityResultContracts
- skipcollapsed
- webview
- notification
- 이미지 gps
- prettyJson
Archives
- Today
- Total
Debbi Story
Glide circle 이미지에 테두리선 그리기 본문
728x90
fun <T> ImageView.loadCircularImage(
model: T,
borderSize: Float = 0F,
borderColor: Int = Color.WHITE
) {
Glide.with(context)
.asBitmap()
.load(model)
.apply(RequestOptions.circleCropTransform())
.into(object : BitmapImageViewTarget(this) {
override fun setResource(resource: Bitmap?) {
setImageDrawable(
resource?.run {
RoundedBitmapDrawableFactory.create(
resources,
if (borderSize > 0) {
createBitmapWithBorder(borderSize, borderColor)
} else {
this
}
).apply {
isCircular = true
}
}
)
}
})
}
private fun Bitmap.createBitmapWithBorder(borderSize: Float, borderColor: Int): Bitmap {
val borderOffset = (borderSize * 2).toInt()
val halfWidth = width / 2
val halfHeight = height / 2
val circleRadius = Math.min(halfWidth, halfHeight).toFloat()
val newBitmap = Bitmap.createBitmap(
width + borderOffset,
height + borderOffset,
Bitmap.Config.ARGB_8888
)
// Center coordinates of the image
val centerX = halfWidth + borderSize
val centerY = halfHeight + borderSize
val paint = Paint()
val canvas = Canvas(newBitmap).apply {
// Set transparent initial area
drawARGB(0, 0, 0, 0)
}
// Draw the transparent initial area
paint.isAntiAlias = true
paint.style = Paint.Style.FILL
canvas.drawCircle(centerX, centerY, circleRadius, paint)
// Draw the image
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
canvas.drawBitmap(this, borderSize, borderSize, paint)
// Draw the createBitmapWithBorder
paint.xfermode = null
paint.style = Paint.Style.STROKE
paint.color = borderColor
paint.strokeWidth = borderSize
canvas.drawCircle(centerX, centerY, circleRadius, paint)
return newBitmap
}
'안드로이드 > Tip' 카테고리의 다른 글
Notification badge 설정하기! (0) | 2021.10.26 |
---|---|
ExifInterface 이미지 위치정보 가져오기 (0) | 2021.09.04 |
Navigation Component data전달하기 (0) | 2020.11.10 |
Custom Notification bar 만들기 (0) | 2020.10.28 |
Room Insert시 rowId 얻기 (0) | 2020.10.23 |