Android BitmapDrawable.bitmap与BitmapFactory.decodeResource获取不到原始图像素级真实宽高,Kotlin

Android BitmapDrawable.bitmap与BitmapFactory.decodeResource获取不到原始图像素级真实宽高,Kotlin

当一个图片放在ImageView里面后,用以下方式获取图的宽高:

Kotlin 复制代码
        val bmp1 = (this.drawable as BitmapDrawable).bitmap
        Log.d("fly", "bmp1 w=${bmp1.width} h=${bmp1.height}")

        val bmp2 = BitmapFactory.decodeResource(resources, R.mipmap.image)
        Log.d("fly", "bmp2 w=${bmp2.width} h=${bmp2.height}")

上面两种方式得到的并不是原始图的宽高,而是经过系统压缩采样处理后的宽高,如果需要获取原始图像素级别的宽高,则需要用这种方式:Android BitmapFactory.decodeResource读取原始图片装载成原始宽高Bitmap,Kotlin_bitmapfactory解码宽高-CSDN博客

以上三种方式读取的"原始"图宽高值输出:

最后一个输出的原始图的真实宽高。

Android BitmapFactory.decodeResource读取原始图片装载成原始宽高Bitmap,Kotlin_bitmapfactory解码宽高-CSDN博客文章浏览阅读849次。文章浏览阅读1.8k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android Drawable 转化成 Bitmap-CSDN博客。_bitmapfactory解码宽高https://blog.csdn.net/zhangphil/article/details/134449577Android Drawable转BitmapDrawable再提取Bitmap,Kotlin-CSDN博客文章浏览阅读723次。*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android传递Bitmap的两种简单方式及其缺陷_android上传bitmap_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/132351440Android BitmapFactory.decodeResource读取原始图片装载成原始宽高Bitmap,Kotlin_bitmapfactory解码宽高-CSDN博客文章浏览阅读849次。文章浏览阅读1.8k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android Drawable 转化成 Bitmap-CSDN博客。_bitmapfactory解码宽高https://blog.csdn.net/zhangphil/article/details/134449577

相关推荐
stevenzqzq1 小时前
Android Jetpack Compose 列表开发指南:为什么你不需要再为底部 Item 写额外间距
android·android jetpack
撩得Android一次心动9 小时前
Jetpack Compose 知识点整理2【个人用】
android·笔记·学习·kotlin·compose
是真的小外套10 小时前
2024年软考中级信息安全工程师|选择题考点+案例分析真题解析(含答案)
android·网络
用户20187928316712 小时前
一文讲透 Android Native Heap 监控原理:一间"只进不出"的仓库,和总部派来的侦探
android
Ehtan_Zheng12 小时前
Kotlin 伴生块:Android 项目怎么用,迁移时要注意什么
kotlin
JMchen12 小时前
【Jetpack 内核实战 02】ViewModel:生命周期管理与数据持久化核心实战
kotlin·android studio·android jetpack
YB137513 小时前
Jetpack Compose 动画animate*AsState
android
高晶13 小时前
Android 通讯录应用开发实战:从零搭建 SQLite 数据持久化完整项目
android·设计模式·前端框架
隐擎fox13 小时前
深入 Android 移动端风控与协议层对抗:内核级虚拟环境检测、网络堆栈特征伪装与住宅 IP 协同实战
android·网络·python·网络协议·tcp/ip