在另一個UIImage上添加UIImage

[英]Add UIImage on top of another UIImage


i have 2 images: first one is the user personal image, the second one is an icon (badge).

我有2張圖片:第一張是用戶個人圖片,第二張是圖標(徽章)。

i want to add the second uiimage (icon) on the bottom left corner of the first uiimage (user's image) and save them into a new Uiimage.

我想在第一個uiimage(用戶的圖像)的左下角添加第二個uiimage(圖標)並將它們保存到新的Uiimage中。

thanks

2 个解决方案

#1


28  

Try this method:

試試這個方法:

-(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;
}

You can use it by:

你可以用它來:

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

#2


2  

Try this:

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();

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/05/09/60892855d4a513a335d59deafcddab56.html



 
  © 2014-2022 ITdaan.com 联系我们: