iPhone, how does one overlay one image onto another to create a new image to save? (watermark)

前端 未结 5 1199
逝去的感伤
逝去的感伤 2021-01-30 00:13

Basically I want to take an image that the user chooses from their photo library and then apply a watermark, a triangle in the lower right that has the app name on it. I have th

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 00:54

    You can use this method, which is very dynamic and you can specify the starting position of the second image and total size of the image.

    -(UIImage *) addImageToImage:(UIImage *)img withImage2:(UIImage *)img2 andRect:(CGRect)cropRect withImageWidth:(int) width{
    
        CGSize size = CGSizeMake(width,40);
        UIGraphicsBeginImageContext(size);
    
        CGPoint pointImg1 = CGPointMake(0,0);
        [img drawAtPoint:pointImg1];
    
        CGPoint pointImg2 = cropRect.origin;
        [img2 drawAtPoint: pointImg2];
    
        UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return result;
    
    }
    

提交回复
热议问题