Android Coil 3拦截器Interceptor计算单次请求耗时,Kotlin

Android Coil 3拦截器Interceptor计算单次请求耗时,Kotlin

Kotlin 复制代码
import android.content.Context
import android.util.Log
import coil3.intercept.Interceptor
import coil3.request.ImageResult

class MyInterceptor : Interceptor {
    companion object {
        const val TAG = "fly/MyInterceptor"
    }

    private var mCtx: Context? = null

    constructor(ctx: Context) {
        mCtx = ctx
    }

    override suspend fun intercept(chain: Interceptor.Chain): ImageResult {

        val t = System.currentTimeMillis()
        val result = chain.proceed()
        Log.d(TAG, "耗时:${System.currentTimeMillis() - t} ms, ${chain.request.data}")

        return result
    }
}
Kotlin 复制代码
        mImageLoader = ImageLoader.Builder(ctx)

            ...
            .components {
                ...

                add(MyInterceptor(ctx))
                
            }.build()

Android Coil3视频封面抽取封面帧存Disk缓存,Kotlin(2)-CSDN博客文章浏览阅读444次,点赞9次,收藏14次。本文介绍了基于Coil3的Android视频封面抽取优化方案,重点改进了磁盘缓存性能。通过将封面帧从PNG无损格式改为JPEG有损压缩(质量80),使缓存文件大小缩减至原先的1/10,显著提升了读写速度。核心实现包括:1)使用FFmpegMediaMetadataRetriever快速抽取视频首帧;2)自定义Bitmap压缩参数(Bitmap.CompressFormat.JPEG);3)采用缓冲流(BufferedOutputStream)处理磁盘缓存写入。该方案在保持图像质量的同时优化了I/O性能,适用https://blog.csdn.net/zhangphil/article/details/150494282

相关推荐
恋猫de小郭10 分钟前
Flutter + EmbeddingGemma 2,谷歌发布完全端侧的 AI Edge Foresight
android·前端·flutter
ZealSinger1 小时前
Kotlin2.4迁移context parameters
kotlin·协程·迁移·kotlin2.4
墨天梦1 小时前
B16_Material主题与可访问交互
android·kotlin·交互
弯_弯2 小时前
企业知识库 RAG 落地:从 Demo 到生产,四条工程链路与参数级自查
android·java·javascript
晚风叙码3 小时前
MySQL 表的约束详解:从空属性到外键
android·数据库·mysql·adb
alexhilton13 小时前
模块化Jetpack Compose架构
android·kotlin·android jetpack
厮年断弦16 小时前
AI 辅助开发实录:一周做完一个 Android 本地音乐播放器,这些坑替你踩了
android
hai_android16 小时前
InputStage 责任链核心执行流程
android·android studio·android jetpack
mmsx19 小时前
Android 测绘计算工程化:七四参数、高程拟合与单位系统
android·kotlin
我是场21 小时前
我的NPI项目之-Touch的EE特性
android·arm开发