Android获取原始图片Bitmap的宽高大小尺寸,Kotlin

Android获取原始图片Bitmap的宽高大小尺寸,Kotlin

Kotlin 复制代码
                    val options = BitmapFactory.Options()
                    options.inJustDecodeBounds = true

                    val decodeBmp = BitmapFactory.decodeResource(resources, R.mipmap.p1, options)
                    //此时,decode出来的decodeBmp宽高并不是原始图的宽高。
                    //options里面的宽高才是原始图片的宽高
                    val bmpWidth = options.outWidth
                    val bmpHeight = options.outHeight
                    Log.d(TAG, "原始图片宽高 ${bmpWidth} ${bmpHeight}")

下面的代码是告诉Android,只解析宽高尺寸,不decode原始图片文件:

Kotlin 复制代码
                    val options = BitmapFactory.Options()
                    options.inJustDecodeBounds = true

然后从options里面读原始图片的宽高尺寸。

Android大图片之缩略图,以及对原图按照指定宽高裁剪成缩略图-CSDN博客文章浏览阅读5.3k次。《Android大图片之变换缩略图,以及对原始大图片按照指定宽、高裁剪成缩略图》在Android的ImageView加载图像资源过程中,出于性能和内存开销的需要,有时候需要把一个原始的超大图片按照一定比例等比例缩放成较小的缩略图,或者需要把原始的超大图片,裁剪成指定宽高值的较小图片,针对这种开发需求,可以使用Android SDK自身提供的工具类:ThumbnailUtils完成。https://blog.csdn.net/zhangphil/article/details/47857495Android ByteBuffer Bitmap byte[] convert,Kotlin_bitmap bytebuffer-CSDN博客文章浏览阅读593次。Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();_bitmap bytebufferhttps://blog.csdn.net/zhangphil/article/details/132699647Android Drawable 转化成 Bitmap-CSDN博客文章浏览阅读1.8k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmaphttps://blog.csdn.net/zhangphil/article/details/43767535

相关推荐
符哥20082 小时前
新能源智能充电桩与 Android/iOS App 蓝牙通信协议
android·ios
JMchen1232 小时前
自定义View性能优化:从60fps到120fps的进阶之路
android·经验分享·性能优化·kotlin·自定义view
vistaup3 小时前
DevEco Studio 鸿蒙 HAR本地引入相互依赖问题解决
android·华为·harmonyos
常利兵3 小时前
Android 开发秘籍:用Tint为Icon动态变色
android
奔跑吧 android4 小时前
【车载audio】【CarAudioService 05】【车载 Android 系统调试深度指南:解析 dumpsys car_service】
android·audio·audioflinger·aosp15·车载音频·车载audio·car_service
shuangrenlong4 小时前
androidstudio gradle文件报红
android
Digitally4 小时前
如何通过蓝牙将 iPhone 上的照片传输到 Android
android·ios·iphone
常利兵4 小时前
Android Intent.setAction失效报错排查与修复全方案
android
耶叶4 小时前
Kotlin 的 Generics
kotlin
低调小一4 小时前
RecyclerView 缓存与复用机制:从一次滑动讲明白(2026 版)
android·recyclerview