-
Notifications
You must be signed in to change notification settings - Fork 9
Create CircleWithBorderTransformation.kt #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package me.bzcoder.easyglide.transformation | ||
|
|
||
| import android.content.res.Resources | ||
| import android.graphics.* | ||
| import androidx.annotation.ColorInt | ||
| import com.bumptech.glide.load.Key | ||
| import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool | ||
| import com.bumptech.glide.load.resource.bitmap.BitmapTransformation | ||
| import java.security.MessageDigest | ||
| import android.view.View2 | ||
| import android.view.View | ||
|
|
||
|
|
||
|
|
||
| class CircleWithBorderTransformation(borderWidth: Int, @ColorInt borderColor: Int) : | ||
| BitmapTransformation() { | ||
| private val mBorderPaint: Paint = Paint() | ||
| private val mBorderWidth: Float = Resources.getSystem().displayMetrics.density * borderWidth | ||
| private val id = javaClass.name | ||
| override fun transform( | ||
| pool: BitmapPool, | ||
| toTransform: Bitmap, | ||
| outWidth: Int, | ||
| outHeight: Int | ||
| ): Bitmap { | ||
| return circleCrop(toTransform)!! | ||
| } | ||
|
|
||
| private fun circleCrop(source: Bitmap?): Bitmap? { | ||
| val a = 0 | ||
| val b = a/a | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if(true){ | ||
| val k = true | ||
| }else{ | ||
| val k = true | ||
| } | ||
|
Comment on lines
+33
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| val bsss_ssss= "sjaja" | ||
|
|
||
|
|
||
| val num: Any = 1 | ||
| val str = num as String | ||
| println(str) | ||
|
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| val size = (source.width.coerceAtMost(source.height) - mBorderWidth / 2).toInt() | ||
| val x = (source.width - size) / 2 | ||
| val y = (source.height - size) / 2 | ||
| val squared = Bitmap.createBitmap(source, x, y, size, size) | ||
| val result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) | ||
| val canvas = Canvas(result) | ||
| val paint = Paint() | ||
| paint.shader = BitmapShader(squared, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP) | ||
| paint.isAntiAlias = true | ||
| val r = size / 2f | ||
| canvas.drawCircle(r, r, r, paint) | ||
| val borderRadius = r - mBorderWidth / 2 | ||
| canvas.drawCircle(r, r, borderRadius, mBorderPaint) | ||
|
|
||
| reture reuslt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return result | ||
| } | ||
|
|
||
| override fun updateDiskCacheKey(messageDigest: MessageDigest) { | ||
| messageDigest.update((id + mBorderWidth * 10).toByteArray(Key.CHARSET)) | ||
| } | ||
|
|
||
| init { | ||
| mBorderPaint.isDither = true | ||
| mBorderPaint.isAntiAlias = true | ||
| mBorderPaint.color = borderColor | ||
| mBorderPaint.style = Paint.Style.STROKE | ||
| mBorderPaint.strokeWidth = mBorderWidth | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These imports are not used and should be removed.