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

相关推荐
雨白6 小时前
深入理解 Java/Kotlin 反射、注解与泛型:从原理到实战
android·架构
喜欢打篮球的普通人10 小时前
LLVM Backend Lowering 从入门到实战:把 IR 变成机器码的完整链路
android·java·数据库
萝卜er13 小时前
BroadcastReceiver 静态注册与动态注册-《Android深水区(七)》
android
萝卜er14 小时前
ContentProvider 与跨进程数据访问-《Android深水区(八)》
android
萝卜er14 小时前
Service、前台服务与后台限制-《Android深水区(六)》
android
萝卜er14 小时前
Android 存储体系与分区存储-《Android深水区(十二)》
android
会编程的吕洞宾14 小时前
DeepAgents In Action学习(Second)
android·java·学习
太子釢14 小时前
用 AI 完整实现 Github 客户端:基于 KMP + SwiftUI + Compose
android·人工智能·ios
汪海游龙15 小时前
本地源码还是 Maven 版本?Gradle composite build 双轨依赖的正确接法
android·ci/cd·kotlin
k3x1n15 小时前
三星安卓系统BUG排查记录:云闪付、铁路12306、个人所得税、中国移动等App,长期闪退的根本原因分析
android·逆向