从两个较小的UIImages创建UIImage

时间:2012-09-27 16:13:40

标签: ios uiimage core-graphics image-manipulation

我有两个UIImage个实例。如何创建第三个UIImage只是将两个原始图像拼接在一起?我希望顶部的第一个图像和底部的第二个图像使得顶部图像的底部边缘与底部图像的顶部边缘齐平。

1 个答案:

答案 0 :(得分:6)

这样的事情应该有效(我还没有测试过)

-(UIImage *)imageWithTopImage:(UIImage *)topImage bottomImage:(UIImage *)bottomImage
{
    UIGraphicsBeginImageContext(CGSizeMake(topImage.size.width, topImage.size.height + bottomImage.size.height);
    [topImage drawInRect:CGRectMake(0, 0, topImage.size.width, topImage.size.height)];
    [bottomImage drawInRect:CGRectMake(0, topImage.size.width, bottomImage.size.width, bottomImage.size.height)];
    UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return combinedImage;
}