Android Glide load origin Bitmap, Kotlin

Android Glide load origin Bitmap, Kotlin

Kotlin 复制代码
        Glide.with(this)
            .asBitmap()
            .load(R.mipmap.p)
            .addListener(object : RequestListener<Bitmap> {
                override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>, isFirstResource: Boolean): Boolean {
                    return false
                }

                override fun onResourceReady(
                    resource: Bitmap,
                    model: Any,
                    target: Target<Bitmap>?,
                    dataSource: DataSource,
                    isFirstResource: Boolean
                ): Boolean {
                    Log.d("fly", "a ${resource.height} ${resource.width}")
                    return false
                }
            })
            .preload()

        Glide.with(this)
            .asBitmap()
            .load(R.mipmap.p)
            .into(object : CustomTarget<Bitmap>() {
                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    Log.d("fly", "b ${resource.height} ${resource.width}")
                }

                override fun onLoadCleared(placeholder: Drawable?) {

                }
            })

        val target = PreloadTarget.obtain<Bitmap>(Glide.with(this), 150, 250)
        Glide.with(this)
            .asBitmap()
            .load(R.mipmap.p)
            .addListener(object : RequestListener<Bitmap> {
                override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>, isFirstResource: Boolean): Boolean {
                    return false
                }

                override fun onResourceReady(
                    resource: Bitmap,
                    model: Any,
                    target: Target<Bitmap>?,
                    dataSource: DataSource,
                    isFirstResource: Boolean
                ): Boolean {
                    Log.d("fly", "c ${resource.height} ${resource.width}")
                    return false
                }
            })
            .into(target)

D a 2414 3697

D b 2414 3697

D c 250 383

Android Glide CustomTarget ,kotlin-CSDN博客文章浏览阅读1.8k次。文章介绍了如何在Android应用中使用Glide库,特别是通过Kotlin实现CustomTarget来处理Bitmap,将加载的图片设置到ImageView,并讨论了如何处理头像的圆形显示。此外,还提到了Glide的预加载功能和图片缓存策略。https://blog.csdn.net/zhangphil/article/details/131661819

Android Glide CustomTarget与PreloadTarget,Kotlin-CSDN博客文章浏览阅读479次,点赞5次,收藏3次。【代码】Android Paging 3,kotlin(1)在实际的开发中,虽然Glide解决了快速加载图片的问题,但还有一个问题悬而未决:比如用户的头像,往往用户的头像是从服务器端读出的一个普通矩形图片,但是现在的设计一般要求在APP端的用户头像显示成圆形头像,那么此时虽然Glide可以加载,但加载出来的是一个矩形,如果要Glide_android 毛玻璃圆角。现在结合他人的代码加以修改,给出一个以原始图形中心为原点,修剪图片为头像的工具类,此类可以直接在布局文件中加载使用,比。容易丢失之前加载的内容。_android glide customtargethttps://blog.csdn.net/zhangphil/article/details/139506785

相关推荐
FungLeo10 小时前
FengCMS · PHP+MySQL 升级实录 · 危险默认值之殇:root/123456、认证码 8888 写进配置加载器
android·mysql·php·安全加固·fengcms
yz_aiks11 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)
android·linux·python·智能手机·ssh·termux
booboosui19 小时前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白1 天前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android2 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m2 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui2 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
用户60709759149062 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭2 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
JMchen1232 天前
【Android 性能优化实战 60 讲】12 异步 Inflate 实战与痛击:源码拆解原生瓶颈,手写增强版布局预加载框架
android·性能优化·实战·启动优化·异步inflate·x2c