当前位置:网站首页>Bitmap加载内存分析
Bitmap加载内存分析
2022-06-23 22:10:00 【MirkoWug】
一、Bitmap内存
1.Bitmap内存的计算方式
1.decodeResource 从drawable、mipmap这种对应的文件目录中加载图片Bitamp 占用内存大小 = 宽度像素 x (inTargetDensity / inDensity) x 高度像素 x (inTargetDensity / inDensity)x 一个像素所占的内存inTargetDensity :设备的dpiinDensity :当前文件所在drawable文件夹目录 对应的dpi
一个像素所占的内存,有以下几种像素格式:
ALPHA_8 1byte
ARGB_4444 2byte
ARGB_8888 4byte
RGB_565 2byte
2.从本地磁盘 、asset、等方式中加载图片Bitamp 占用内存大小 = 宽度像素 x 高度像素 x 一个像素所占的内存
注意:当使用第三方库时,则不能用这些公式来计算,因为三方库内部会重新对内存进行优化。
eg:
fresco:不管图片来源是哪里,即使是 res,图片占用的内存大小仍旧以原图的分辨率计算。
Glide:如果有设置图片显示的控件,那么会自动按照控件的大小,降低图片的分辨率加载。图片来源是 res 的分辨率转换规则对它也无效。
注意:Bitmap的内存大小 和像素大小是不一样的。
内存大小= 像素大小(即图片宽 x 高)x 一个像素所占内存
二、影响内存的二个因素
1、图片分辨率,也就是图片尺寸
2、像素点所占内存大小,对应4种像素格式
所以我在做内存优化时,可以从这二方面来入手:
1.减小图片的尺寸
2.调整为占用内存更小的像素格式。
实际开发中,我们更倾向第一种,因为修改像素格式,会导致图片质量下降,导致失真。
而对第一种,可以参考 Luban
三、结论
- 图片来源是 res 内的不同资源目录时,系统会根据设备当前的 dpi 值以及资源目录所对应的 dpi 值,做一次分辨率转换,规则如下:新分辨率 = 原图横向分辨率 * (设备的 dpi / 目录对应的 dpi ) * 原图纵向分辨率 * (设备的 dpi / 目录对应的 dpi )。
- 其他图片的来源,如磁盘,文件,流等,均按照原图的分辨率来进行计算图片的内存大小。
- jpg、png 只是图片的容器,图片文件本身的存储大小与它所占用的内存大小没有什么关系。
参考
1.Bitmap分析
2.https://www.cnblogs.com/dasusu/p/9789389.html
3.Bitmap分析
边栏推荐
- The fortress machine installs pytorch, mmcv, and mmclassification, and trains its own data sets
- pyspark on hpc
- 【Try to Hack】masscan
- Several cases of index invalidation caused by MySQL
- 在OpenCloudOS使用snap安装.NET 6
- 国家邮政局等三部门:加强涉邮政快递个人信息安全治理,推行隐私面单、虚拟号码等个人信息去标识化技术
- 【HackTheBox】 meow
- PHP timestamp
- Common core resource objects of kubernetes
- 【HackTheBox】Fawn
猜你喜欢

Flutter中的GetX状态管理用起来真的那么香吗?

FANUC机器人SRVO-050碰撞检测报警原因分析及处理对策(亲测可用)

【Xilinx AX7103 MicroBalze学习笔记6】MicroBlaze 自定义 IP 核封装实验

C#/VB. Net word to text

Bilibili × Blue bridge cloud course | online programming practice competition is new!

【设计】1359- Umi3 如何实现插件化架构
Detailed process of deploying redis cluster and micro service project in docker

生鲜前置仓的面子和里子

Ambire 指南:Arbitrum 奥德赛活动开始!第一周——跨链桥

C# Winform 自定义进度条ProgressBar
随机推荐
AIX系统月维护查什么(二)
Cs5213 HDMI to VGA with audio signal output scheme
Short video enters the hinterland of online music
Go language core 36 lectures (go language practice and application 23) -- learning notes
The sandbox week is coming!
Phpmailer sends mail PHP
Operation and maintenance failure experience sharing
Eight models of data analysis: detailed PEST model
Data interpretation! Ideal L9 sprints to "sell more than 10000 yuan a month" to grab share from BBA
HDLBits->Circuits->Arithmetic Circuitd->3-bit binary adder
How to batch generate flattermark barcode
The fortress computer is connected to the server normally, but what's wrong with the black screen? What should I do?
How to judge the video frame type in h265 in golang development
Oracle关闭回收站
Bilibili×蓝桥云课|线上编程实战赛全新上新!
How can manufacturing enterprises go to the cloud?
Payment industry tuyere project: smart digital operation 3.0
Production of labels for table products
国内外最好的12款项目管理系统优劣势分析
“山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛