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

相关推荐
灿烂阳光g1 小时前
SELinux 策略文件编写
android·linux
.豆鲨包1 小时前
【Android】Viewpager2实现无限轮播图
android·java
xiangxiongfly9151 小时前
Android CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout实现折叠置顶效果
android·折叠
柿蒂1 小时前
从if-else和switch,聊聊“八股“的作用
android·java·kotlin
Jerry3 小时前
Compose 5 个简短动画,让您的应用脱颖而出
android
PenguinLetsGo3 小时前
你的App是否有出现过幽灵调用?
android
没有了遇见4 小时前
Android ViewPager2 嵌套 RecyclerView 滑动冲突解决方案
android
咖啡の猫4 小时前
Android开发-选择按钮
android·gitee
火柴就是我5 小时前
android 以maven的方式 引入本地的aar
android
过-眼-云-烟5 小时前
新版Android Studio能打包但无法run ‘app‘,编译通过后手机中没有安装,顶部一直转圈
android·ide·android studio