CGContextDrawImage(context, CGRectMake(0, 0, _w, _h), handle());
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, CGRectMake(0, 0, other->width(), other->height()), over);
但是,这只会着色,而不会遮罩。因此,我将遮罩图像中的alpha提取为CGImage mask灰度图像(使用CGDataProvider),并将其用作上下文中的遮罩:
// "mask" is "other"'s alpha channel as an inverted grayscale image
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(0, 0, other->width(), other->height()), mask);
CGImageRelease(mask);
CGContextDrawImage(context, CGRectMake(0, 0, _w, _h), handle());
CGContextRestoreGState(context); // Don't apply the clip mask to 'other', since it already has it
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, CGRectMake(0, 0, other->width(), other->height()), other->handle());
不过,看起来还是不对。图像变得
;相乘后的图像至少应该更暗吗?图像预览位置:
http://dl.dropbox.com/u/6775/multiply/index.html
提前感谢您的启示:)