简体   繁体   English

哪一个是更快的颜色过滤或在Android中使用不同的drawable?

[英]Which one is faster Color Filtering or use different drawables in android?

i'm using icons on recyclerview row items.And i'm changing icon's colors with Color Filter option in android but i'm wondering which one is faster and better ? 我在recyclerview行项目上使用图标。并且我正在使用android中的“ 颜色滤镜”选项更改图标的颜色,但我想知道哪一个更快 更好

  • different colored drawables 不同颜色的绘画
  • (run-time) color filter on white drawable icon (运行时)白色可绘制图标上的滤色器

I already use color filtering on white drawable but it sometimes does not appear in list row till refresh recyclerview so i just think about to use different drawables. 我已经在白色可绘制对象上使用了颜色过滤,但是有时直到刷新recyclerview时它才出现在列表行中,所以我只是考虑使用其他可绘制对象。 thank you for your interest... 感谢您的关注...

It is hard to say, but I would say that changing the drawable is faster, and this is why I think this: 很难说,但是我想说改变可绘制对象的速度更快,这就是为什么我这样认为:

  • in order to filter a image the system has to read each pixel from RAM, transform each RGB component in order to add the tint (it's not as simple as adding +3 to the intensity of each pixel), and then write each pixel 为了过滤图像,系统必须从RAM读取每个像素,对每个RGB分量进行转换,以添加色调(这不像向每个像素的强度添加+3那样简单),然后写入每个像素

  • changing the drawable implies reading from the flash memory and load it into ram 更改drawable意味着从闪存中读取并将其加载到ram中

The thing is that flash storage on mobile devices is pretty fast too these days so I consider it's faster to load than tint images. 事实是,如今移动设备上的闪存存储也非常快,因此我认为它的加载速度比着色图像要快。

BUT it depends on how you create the layout. 但是这取决于您如何创建布局。 If you load a image the Android system will recalculate the whole layout if other elements change position when you change the drawable. 如果您加载图片,则当更改可绘制对象时其他元素更改位置时,Android系统将重新计算整个布局。 I don't think they wrote code to keep the layout the same if the new drawable has the same size as the last one, and this will involve more calculations than a simple tinting. 我认为如果新的drawable具有与上一个相同的大小,他们不会编写代码来使布局保持不变,这将涉及比简单着色更多的计算。

彩色滤光效果更好,因为它使用GPU(因此速度更快),并且可以降低最终apk的大小,但是有时使用硬件加速器会由于内存泄漏,可绘制的大小,不良的设计和..而使应用程序缓慢而缓慢。 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM