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

相关推荐
墨天梦2 小时前
D05_ViewModel与单向数据流
android·kotlin
蒸鱼Yuzheng3 小时前
Android 构建可复现性:APK 指纹、文件级差异与供应链审计
android·apk·devops·软件供应链·可复现构建
墨天梦5 小时前
D03_Compose列表与稳定身份
android·gitee·kotlin
萌新杰少6 小时前
Kuikly股票查看软件开发体验——SaiRen
android·kotlin·客户端
vilya6 小时前
把 Python 塞进 APK:Chaquopy 打包实践
android·python
用户92817267390166 小时前
Android Compose版本的AI组件库来了。
android·kotlin
知昂七昂6 小时前
00-02:AOSP 源码阅读环境与检索方法论源码剖析(Android 16 / aosp-main)
android
知昂七昂6 小时前
00-01:AOSP 源码仓库结构与 repo 工作流源码剖析(Android 16 / aosp-main)
android·google
跨境数据猎手6 小时前
Android Native 层黑盒调用实战:unidbg 模拟执行 so 的原理
android
镜象科技7 小时前
中小学AI心理健康解决方案服务商怎么选?2026年选型参考
android·java·人工智能