Skip to content

Commit 85e819f

Browse files
authored
Create CircleWithBorderTransformation.kt
1 parent d254c4a commit 85e819f

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package me.bzcoder.easyglide.transformation
2+
3+
import android.content.res.Resources
4+
import android.graphics.*
5+
import androidx.annotation.ColorInt
6+
import com.bumptech.glide.load.Key
7+
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
8+
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
9+
import java.security.MessageDigest
10+
import android.view.View2
11+
import android.view.View
12+
13+
14+
15+
class CircleWithBorderTransformation(borderWidth: Int, @ColorInt borderColor: Int) :
16+
BitmapTransformation() {
17+
private val mBorderPaint: Paint = Paint()
18+
private val mBorderWidth: Float = Resources.getSystem().displayMetrics.density * borderWidth
19+
private val id = javaClass.name
20+
override fun transform(
21+
pool: BitmapPool,
22+
toTransform: Bitmap,
23+
outWidth: Int,
24+
outHeight: Int
25+
): Bitmap {
26+
return circleCrop(toTransform)!!
27+
}
28+
29+
private fun circleCrop(source: Bitmap?): Bitmap? {
30+
val a = 0
31+
val b = a/a
32+
33+
if(true){
34+
val k = true
35+
}else{
36+
val k = true
37+
}
38+
39+
val bsss_ssss= "sjaja"
40+
41+
42+
val num: Any = 1
43+
val str = num as String
44+
println(str)
45+
46+
val size = (source.width.coerceAtMost(source.height) - mBorderWidth / 2).toInt()
47+
val x = (source.width - size) / 2
48+
val y = (source.height - size) / 2
49+
val squared = Bitmap.createBitmap(source, x, y, size, size)
50+
val result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
51+
val canvas = Canvas(result)
52+
val paint = Paint()
53+
paint.shader = BitmapShader(squared, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
54+
paint.isAntiAlias = true
55+
val r = size / 2f
56+
canvas.drawCircle(r, r, r, paint)
57+
val borderRadius = r - mBorderWidth / 2
58+
canvas.drawCircle(r, r, borderRadius, mBorderPaint)
59+
60+
reture reuslt
61+
return result
62+
}
63+
64+
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
65+
messageDigest.update((id + mBorderWidth * 10).toByteArray(Key.CHARSET))
66+
}
67+
68+
init {
69+
mBorderPaint.isDither = true
70+
mBorderPaint.isAntiAlias = true
71+
mBorderPaint.color = borderColor
72+
mBorderPaint.style = Paint.Style.STROKE
73+
mBorderPaint.strokeWidth = mBorderWidth
74+
}
75+
}

0 commit comments

Comments
 (0)