Android从Drawable资源Id直接生成Bitmap,Kotlin

Android从Drawable资源Id直接生成Bitmap,Kotlin

Kotlin 复制代码
        val t1 = System.currentTimeMillis()
        val bmp = getBmpFromDrawId(this, R.mipmap.ic_launcher_round)
        Log.d("fly", "1 ${bmp?.byteCount} h=${bmp?.height} w=${bmp?.width} cost time=${System.currentTimeMillis() - t1}")

        val t2 = System.currentTimeMillis()
        val scaleBmp = Bitmap.createScaledBitmap(bmp!!, 800, 800, true)
        Log.d("fly", "2 ${scaleBmp.byteCount} h=${scaleBmp.height} w=${scaleBmp.width} cost time=${System.currentTimeMillis() - t2}")
Kotlin 复制代码
    private fun getBmpFromDrawId(context: Context, drawId: Int): Bitmap? {
        val drawable = ContextCompat.getDrawable(context, drawId)
        val bitmap = drawable?.let {
            Bitmap.createBitmap(
                it.intrinsicWidth,
                it.intrinsicHeight,
                Bitmap.Config.ARGB_8888
            )
        }

        val canvas = bitmap?.let { Canvas(it) }
        if (canvas != null) {
            drawable.setBounds(0, 0, canvas.width, canvas.height)
            drawable.draw(canvas)
        }

        return bitmap
    }

Android Drawable转BitmapDrawable再提取Bitmap,Kotlin_android drawable to bitmap-CSDN博客文章浏览阅读864次。*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android传递Bitmap的两种简单方式及其缺陷_android上传bitmap_zhangphil的博客-CSDN博客。_android drawable to bitmaphttps://blog.csdn.net/zhangphil/article/details/132351440

Android Drawable 转化成 Bitmap_android drawable 转为 bitmap-CSDN博客文章浏览阅读2k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap_android drawable 转为 bitmaphttps://blog.csdn.net/zhangphil/article/details/43767535

相关推荐
一过菜只因3 小时前
MySql Jdbc
android·数据库·mysql
音视频牛哥4 小时前
Android音视频开发:基于 Camera2 API 实现RTMP推流、RTSP服务与录像一体化方案
android·音视频·安卓camera2推流·安卓camera2推送rtmp·安卓camera2 rtsp·安卓camera2录制mp4·安卓实现ipc摄像头
2501_937145414 小时前
2025 IPTV 源码优化版:稳定兼容 + 智能升级
android·源码·电视盒子·源代码管理·机顶盒
Nerve8 小时前
FluxImageLoader : 基于Coil3封装的 Android 图片加载库,旨在提供简单、高效且功能丰富的图片加载解决方案
android·android jetpack
元气满满-樱8 小时前
MySQL基础管理
android·mysql·adb
summerkissyou19878 小时前
android13-audio-AudioTrack-写数据流程
android·音视频
董三毛11 小时前
Kotlin Coroutine 底层实现原理
android
L1087011 小时前
AutoJsPro GoogleMaterial3 M3组件使用示例
android
枣把儿12 小时前
「zotepad」用Gemini3pro写出一个高效写作和发文的记事本应用
android·前端·nuxt.js
明川12 小时前
Android Gradle 学习 - 生命周期和Task
android·前端·gradle