12

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

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

谢谢

4

2 回答 2

28

试试这个方法:

-(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];
于 2012-05-09T20:01:58.230 回答
2

尝试这个:

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();
于 2012-05-09T19:56:48.573 回答