我有两个UIImage
个实例。如何创建第三个UIImage
只是将两个原始图像拼接在一起?我希望顶部的第一个图像和底部的第二个图像使得顶部图像的底部边缘与底部图像的顶部边缘齐平。
答案 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;
}