在android中获取和设置位图颜色表
我有一堆小的两种颜色的 png 图像,我想有效地将两种颜色中的一种更改为另一种颜色。说RED =>蓝色。
我知道我可以循环每个像素或使用 Bitmap.setXfermode 来执行此操作,但在这样一个简单的问题上感觉像是一个很大的浪费。我想要做的是访问文件的标题并直接在颜色表中更改它。这暗示 png:
已被索引 http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap:
注意:位图文件可以通过 aapt 工具通过无损图像压缩自动优化。例如,不需要超过 256 色的真彩色 PNG 可以通过调色板转换为 8 位 PNG。这将产生同等质量的图像,但需要更少的内存。因此请注意,放置在该目录中的图像二进制文件在构建过程中可能会发生变化。如果您打算将图像作为位流读取以便将其转换为位图,请将图像放入 res/raw/ 文件夹中,这样它们将不会被优化。
我放入“项目”中的文件是索引的 png 图像,因此我确信它们实际上已索引并且确实有颜色表。在创建 Bitmap 对象之前,我是否必须将文件作为二进制数据读取并进行操作?如果不是这样的话,我真的更喜欢,但有一些隐藏的 Bitmap.switchColor (Col1, Col2
);就可以做到这一点,因为我希望能够切换回或切换到第三种颜色。
请仅提供与 android 相关的答案,而不是一般答案,因为我只是在寻找如何使用 android 类在 android 中执行此操作。
提前致谢
I've got a bunch of small two colour png images and I'd like to effectively change one of the two colours to another one. Say RED => BLUE
.
I know I can either loop over each pixel or use Bitmap.setXfermode
to do this but it feels like a big waste on such a simple problem. What I want to do is to access the header of the file and change it in the colour table directly. This hints that png:
s are indexed http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap :
Note: Bitmap files may be automatically optimized with lossless image compression by the aapt tool. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build. If you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ folder instead, where they will not be optimized.
The files I put in the "project" are indexed png images so I know for sure they are in fact indexed and does have a colour table. Will I have to read the files as binary data and manipulate before I make a Bitmap object? I would really prefer if that wasn't the case but there instead is some hidden Bitmap.switchColor (Col1, Col2
); which would do just that since I want to be able to switch back or to a third colour.
Please only android related answers and not general ones since I'm only looking for how to do it in android, using android classes.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论