Well, the answer will rely specifically on knowing the background color. Something like this would work, assuming backgroundColor
and sourceColor
are UIColors:
float blend(float src, float srcAlpha, float background) {
return (background + src * srcAlpha) / 2;
}
UIColor *result = [UIColor colorWithRed:blend([sourceColor red], [sourceColor alpha], [backgroundColor red])
green:blend([sourceColor green], [sourceColor alpha], [backgroundColor green])
blue:blend([sourceColor blue], [sourceColor alpha], [backgroundColor blue])
alpha:1.0f];
While the numbers aren't equal to your example, this is a reasonable blend function that is generic. Without more examples it's hard to know what the curve of your example is. The blend function you're using appears to use a different ratio for each color component, or perhaps your measurement of the resultant color values are being adjusted by the color profile of your screen.