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

相关推荐
uwvwko12 小时前
BUUCTF——web刷题第一页题解
android·前端·数据库·php·web·ctf
fzxwl12 小时前
隆重推荐(Android 和 iOS)UI 自动化工具—Maestro
android·ui·ios
LittleLoveBoy14 小时前
踩坑:uiautomatorviewer.bat 打不开
android
居然是阿宋15 小时前
Android核心系统服务:AMS、WMS、PMS 与 system_server 进程解析
android
CGG9217 小时前
【单例模式】
android·java·单例模式
kp0000018 小时前
PHP弱类型安全漏洞解析与防范指南
android·开发语言·安全·web安全·php·漏洞
编程乐学(Arfan开发工程师)1 天前
06、基础入门-SpringBoot-依赖管理特性
android·spring boot·后端
androidwork1 天前
使用 Kotlin 和 Jetpack Compose 开发 Wear OS 应用的完整指南
android·kotlin
_龙小鱼_1 天前
Kotlin变量与数据类型详解
开发语言·微信·kotlin
繁依Fanyi1 天前
Animaster:一次由 CodeBuddy 主导的 CSS 动画编辑器诞生记
android·前端·css·编辑器·codebuddy首席试玩官