可能重复:
在杯子上合并和包装 UIImage
我有两个图像,我想合并这两个图像,就像我有一个杯子的图像,第二个图像是任何图像现在我想与它合并到杯子我怎么能做到这一点
现在假设杯子是完全白色的,然后我将另一个图像与它合并我应该如何实现这一点????
可能重复:
在杯子上合并和包装 UIImage
我有两个图像,我想合并这两个图像,就像我有一个杯子的图像,第二个图像是任何图像现在我想与它合并到杯子我怎么能做到这一点
现在假设杯子是完全白色的,然后我将另一个图像与它合并我应该如何实现这一点????
Well you could make a custom UIView
and override the - (void)drawRect:(CGRect)rect
and write something like this:
CGContextRef con = UIGraphicsGetCurrentContext();
[self.img1 drawInRect:self.bounds blendMode:kCGBlendModeNormal alpha:1];
[self.img2 drawInRect:self.bounds blendMode:kCGBlendModeDarken alpha:1];
img1 is a UIImage
containing the mug image and img2 is another UIImage
containing the overlay.
Also, check out the other blend modes supported by iOS. (kCGBlendModeDarken
compares each pixel from img1 and img2 and selects the darkest one). For a much better explanation of blendmodes, then the one offered by apple, see http://en.wikipedia.org/wiki/Blend_modes