I would like to multiply r, g, b and the values of two CGImages, use one image as a mask (in its alpha channel) and tint (in rgb channels). I first tried simply:
CGContextDrawImage(context, CGRectMake(0, 0, _w, _h), handle());
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, CGRectMake(0, 0, other->width(), other->height()), over);
However, these are only shades and are not masked. So I extracted the alpha from the masking image into a CGImage grayscale mask image (using CGDataProvider) and used this as a mask in context:
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(0, 0, other->width(), other->height()), mask);
CGImageRelease(mask);
CGContextDrawImage(context, CGRectMake(0, 0, _w, _h), handle());
CGContextRestoreGState(context);
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, CGRectMake(0, 0, other->width(), other->height()), other->handle());
However, it still doesn't look right. The image is getting lighter; if the multiplied image should be at least darker? Image Preview at:http://dl.dropbox.com/u/6775/multiply/index.html
Thanks in advance for the enlightenment :)