Creating a Custom Subclass of ColorFilter?

跟風遠走 提交于 2020-01-24 03:54:06

问题


Okay, so this is somewhat related to my previous question on the ColorMatrixColorFilter, but I feel it's a significantly different question. I'm wondering if there's a way - or rather, how to extend the ColorFilter class to create my own custom color filter. For what I'm needing to accomplish, I need to write a custom filter that will query each pixel, convert its RGB value to HSL or LAB, modify the hue, convert it back to RGB, and set that pixel to the new value.

I'm thinking I could simply write a class that does this, taking in a Drawable and an amount of hue shift to perform, but it would have to be called manually for each and every Drawable, and every state of every Drawable, whereas the ColorFilter seems to handle this nicely. Given the existence of the LightingColorFilter and ColorMatrixColorFilter, it seems like it can be subclassed, but so far my efforts to find any sort of documentation have been futile. I can't seem to find the source code for any of the three (Lighting, ColorMatrix, ColorFilter); I'm thinking they're probably done in native code?

My question is this: How can I properly subclass ColorFilter? If I can't find a good answer for that, if anyone is able to find the source (I've searched Android's git) and post a link to that, that would be helpful as well.

Thanks!


回答1:


As you said, the source code shows ColorFilter use native code so you cannot really subclass it.

There's probably no other way than creating your own class for what you want to do.



来源:https://stackoverflow.com/questions/4372992/creating-a-custom-subclass-of-colorfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!