我有2个图片:第一个是用户个人照片,第二个是图标(徽章)。
我想将第二个UIImage(图标)添加到第一个UIImage(用户的照片)的左下角,并将它们保存为新的UIImage。
谢谢
我有2个图片:第一个是用户个人照片,第二个是图标(徽章)。
我想将第二个UIImage(图标)添加到第一个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();