I am currently porting an application from iOS into Android and I have ran into some difficulties when it comes to image processing.
I have a filter class that is comprised of ImageOverlays and ColorOverlays which are applied in a specific order to a given base Bitmap. Each ColorOverlays has an RGB color value, a BlendModeId, and an alpha value. Each ImageOverlay has an image Bitmap, a BlendModeId, and an alpha/intensity value.
My main problem is that I need to support the following blend modes taken from iOS:
- CGBlendModeNormal
- CGBlendModeMultiply
- CGBlendModeScreen
- CGBlendModeOverlay
- CGBlendModeDarken
- CGBlendModeLighten
- CGBlendModeColorDodge
Some of these have corresponding PorterDuff.Mode types in Android while others do not. What's worse, some of the modes that do exist were introduced in recent versions of Android and I need to run on API level 8.
Trying to build the modes from scratch is extremely inefficient.
Additionally, even with the modes that do exist in API8, I was unable to find methods that blend 2 images but that allow you to specify the intensity of the mask (the alpha value from ImageOverlay). Similarly with ColorOverlays.
The iOS functions I am trying to replicate in Android are
CGContextSetBlendMode(...)
CGContextSetFillColorWithColor(...)
CGContextFillRect(...) - This one is easy
CGContextSetAlpha(...)
I have started looking at small third party libraries that support these blend modes and alpha operations. The most promising one was poelocesar's lib-magick which is supposedly a port of ImageMagick.
While lib-magick did offer most of the desired blend modes (called CompositeOperator
) I was unable to find a way to set intensity values or to do a color fill with a blend mode.
I'm sure somebody has had this problem before. Any help would be appreciated. BTW, Project specifications forbid me from going into OpenGLES.