将UIImage添加到另一个UIImage的顶部

我有2个图像:第一个是用户个人形象,第二个是图标(徽章)。

我想在第一个uiimage(用户的图像)的左下angular添加第二个uiimage(图标),并将它们保存到一个新的Uiimage中。

谢谢

试试这个方法:

-(UIImage *)drawImage:(UIImage*)profileImage withBadge:(UIImage *)badge { UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f); [profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)]; [badge drawInRect:CGRectMake(0, profileImage.size.height - badge.size.height, badge.size.width, badge.size.height)]; UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resultImage; } 

你可以使用它:

 UIImage *myBadgedImage = [self drawImage:profileImage withBadge:badgeImage]; 

尝试这个:

 CGFloat scale = [self currentScale]; if (scale > 1.5) UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, scale); else UIGraphicsBeginImageContext(view.frame.size); [image1 drawInRect:CGRectMake(0, 0, w1, h1)]; [image2 drawInRect:CGRectMake(0, 0, w2, h2)]; UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();