/** * Imagewithbackgroundimage:: * * @param backgroundimage background image name * @param logoimage watermark Image Name * * @return Add watermark image */+ (Instancetype) Imagewithbackgroundimage: (NSString *) backgroundimage withlogoimage: (NSString *) logoImage{UIImage *image = [UIImage imagenamed:backgroundimage]; 1. Open a bitmap-based bitmap context uigraphicsbeginimagecontextwithoptions (image.size, NO, 0.0); 2. Draw background [image drawinrect:cgrectmake (0, 0, Image.size.width, image.size.height)]; 3. Draw Watermark//3.1 Set watermark picture frame UIImage *log = [UIImage imagenamed:logoimage]; CGFloat margin = 5.0; CGFloat scale = 0.2; CGFloat Logow = log.size.width * scale; CGFloat Logoh = log.size.height * scale; CGFloat Logox = Image.size.width-logow-margin; CGFloat Logoy = Image.size.height-logoh-margin; 3.2 Draw Watermark [log drawinrect:cgrectmake (Logox, Logoy, Logow, Logoh)]; 4. Remove the picture from the graphics context UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext (); return newimage;}
iOS add watermarks to pictures