gpt4 book ai didi

Android - png 资源在 android < 4.0 上转换为 ColorDrawable

转载 作者:太空狗 更新时间:2023-10-29 12:45:16 25 4
gpt4 key购买 nike

根据文档 here , 一个 png 资源应该被转换为一个 BitmapDrawable。但是我观察到一个奇怪的行为,其中 只有黑色像素 的 png 文件由于 ClassCastException 而导致崩溃(包装在 InvocationTargetException) 如果我尝试在自定义 View 的构造函数中执行以下操作:

  ...  tempDrawable = typedArr.getDrawable(R.styleable.CustomView_src); // Source points to a png file  Log.i("TestPNGToResource", "Canonical Class Name " + tempDrawable.getClass().getCanonicalName());  tempBitmap = ((BitmapDrawable) tempDrawable).getBitmap();  ...

我在 android 2.2 和 2.3 上看到以下记录

09-24 13:21:37.575: I/TestPNGToResource(532): Canonical Class Name android.graphics.drawable.ColorDrawable

为什么资源没有被转换为 BitmapDrawable?

最佳答案

这是 aapt 执行的优化。它能够识别由单一颜色构成的图像并将它们转换为单一颜色而不是位图。这样可以更节省空间,缩短加载时间等。

关于Android - png 资源在 android < 4.0 上转换为 ColorDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com