如何将两个图像合并为一个图像对象?

时间:2008-12-04 11:36:19

标签: iphone cocoa-touch

如何合并两张图片?

我的意思是我有两张图片:一张小图片和另一张图片。我想在特定点上将小图像添加到大图像上,我需要得到UIImage作为结果。

我尝试了CGCreateImageFromMask,但这会让小图片完全覆盖更大的图像。

1 个答案:

答案 0 :(得分:4)

您需要使用UIGraphicsBeginImageContext()生成CGContextRef,然后使用UIGraphicsGetCurrentContext()获取对它的引用。

现在将当前图像绘制到上下文中。完成后,使用UIGraphicsGetImageFromCurrentContext()从该上下文生成UIImage,并UIGraphicsEndImageContext()进行清理。

请参阅Apple's UIKit Function Reference doc

相关问题