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

相关推荐
Wy. Lsy1 小时前
Kotlin基础学习记录
开发语言·学习·kotlin
小袁拒绝摆烂2 小时前
SQL开窗函数
android·sql·性能优化
apihz3 小时前
VM虚拟机全版本网盘+免费本地网络穿透端口映射实时同步动态家庭IP教程
android·服务器·开发语言·网络·数据库·网络协议·tcp/ip
baidu_247438613 小时前
Android MPAndroidChart使用
android
天平4 小时前
react native现代化组件库的推荐 【持续更新...】
android·前端·react native
apihz5 小时前
通用图片搜索-搜狗源免费API接口使用指南
android·java·python·php·音视频
你过来啊你6 小时前
Android开发中ARouter使用和原理详解
android
apihz7 小时前
腾讯云轻量服务器创建快照免费API接口教程
android·服务器·数据库·python·网络协议·tcp/ip·腾讯云
Kiri霧8 小时前
Noting
android·开发语言·kotlin
东风西巷14 小时前
NealFun安卓版:创意无限,娱乐至上
android·人工智能·智能手机·娱乐·软件需求