当前位置:网站首页>[customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)
[customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)
2022-06-11 04:17:00 【The loneliest person】
### be used Glide To show pictures , You will need to add Transformation To handle the circle of the picture 、 Round corners And other styles ,Transformation There are all kinds of styles , Here we need to achieve the following effect :

* This article encapsulates Transformation Inherited from BitmapTransformation To support Glide.
How to achieve :
/**
* Make the top and bottom borders of the picture wavy
*
* @property waveCorners Wave diameter
*/
class WaveTransformation(private val waveCorners: Int) : BitmapTransformation() {
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
messageDigest.update(ID_BYTES)
}
override fun transform(
pool: BitmapPool,
toTransform: Bitmap,
outWidth: Int,
outHeight: Int
): Bitmap {
val canvasBitmap = Bitmap.createBitmap(
toTransform.width,
toTransform.height,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(canvasBitmap) // Create a palette
val paint = Paint().apply {
isAntiAlias = true
shader = BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
} // Create a brush , Brush content is this Bitmap
// Calculate how many small waves can be divided into
val index = canvas.width / waveCorners
var rectLeft = 0f
try {
TransformationUtils.getBitmapDrawableLock().lock()
// Cycle drawing
for (i in 0 .. index) {
val rect = RectF(
rectLeft,
0f,
(rectLeft + waveCorners).toInt().toFloat(),
canvas.height.toFloat()
)
canvas.drawRoundRect(rect, waveCorners / 2f, waveCorners / 2f, paint)
rectLeft = (rectLeft + waveCorners).toInt().toFloat()
}
// Determine whether the last drawing needs to be performed
if (rectLeft < canvas.width.toFloat()){
val rect = RectF(
rectLeft,
0f,
canvas.width.toFloat(),
canvas.height.toFloat()
)
canvas.drawRoundRect(rect, waveCorners / 2f, waveCorners / 2f, paint)
}
canvas.setBitmap(null)
} finally {
TransformationUtils.getBitmapDrawableLock().unlock()
}
return canvasBitmap
}
companion object {
private const val ID = "WaveTransformation"
private val ID_BYTES = ID.toByteArray(CHARSET)
}
}stay Glide Use in :
val requestOptions =
RequestOptions().transform(CenterCrop(), WaveTransformation(25))
Glide.with(context)
.load(url)
.thumbnail(0.2f)
.apply(requestOptions)
.into(view)Continue packaging :
fun <T>ImageView.loadWaveCorner(url: T, waveCorners: Int) {
if (context != null) {
val requestOptions =
RequestOptions().transform(CenterCrop(), WaveTransformation(waveCorners))
loadImage(context, this, url, requestOptions)
}
}
private fun <T> loadImage(
context: Context,
view: ImageView,
url: T,
requestOptions: RequestOptions,
) {
Glide.with(context)
.load(url)
.thumbnail(0.2f)
.apply(requestOptions)
.into(view)
}One line of code calls :
iv.loadWaveCorner(url, 25)
Reference resources :
Glide: https://github.com/bumptech/glide
Transformations:https://github.com/wasabeef/glide-transformations
Last , Welcome to discuss .
边栏推荐
- A Security Analysis Of Browser Extensions
- 2022-06-10:薯队长从北向南穿过一片红薯地(南北长M,东西宽N),红薯地被划分为1x1的方格, 他可以从北边的任何一个格子出发,到达南边的任何一个格子, 但每一步只能走到东南、正南、西南方向的
- 数字电影的KDM是什么?
- Market prospect analysis and Research Report of nitrogen liquefier in 2022
- It's 2022. When will the "module freedom" be realized?
- Ultra simple cameraX face recognition effect package
- 域名解析耗时是什么?域名解析耗时影响因素有哪些?
- What great open source projects does Google have?
- JVM(7):动态链接、方法的调用、四种方法调用指令区分非虚方法和虚方法、invokedynamic指令的使用
- Market prospect analysis and Research Report of denitrification unit in 2022
猜你喜欢

AI助力,释放法务势能!iTerms合同智审系统重磅发布

JVM (4): active and passive use of classes, internal structure of runtime data area, JVM thread description, PC register

JVM(4):类的主动使用与被动使用、运行时数据区域内部结构、JVM线程说明、PC寄存器

Some differences between people

Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system

Grandpa simayan told you what is called inside roll!

Analysis of zero time technology | discover lightning loan attack

JVM (2): loading process of memory structure and classes

再聊数据中心网络

6. form label
随机推荐
Embedded basic interface -spi
Market prospect analysis and Research Report of integrated scanner in 2022
Embedded basic interface UART
Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system
2022 年 5 月产品大事记
密码找回功能可能存在的问题(补充)
Possible problems with password retrieval function (supplementary)
Pictures that make people feel calm and warm
Esp32 porting lvgl
再聊数据中心网络
JVM (2): loading process of memory structure and classes
邪恶的CSRF
从初代播种到落地生花,5G商用三周年“催生万物”
ESP series module burning firmware
MySQL锁总结
JVM(2):内存结构、类的加载过程
Esp32 development -lvgl uses internal and external fonts
QT日志模块的个性化使用
CES 2022 𞓜 guanghetong LTE module fm101 has obtained two important ce/fcc certifications with excellent performance
June 10, 2022: Captain Shu crosses a sweet potato field from north to South (m long from north to South and N wide from east to West). The sweet potato field is divided into 1x1 squares. He can start