Image plus watermark effect and save to the album
Achieve results
Project download: Githubproject download link
Code:
- (void) Viewdidload {[SuperViewdidload];UIImage*image = [UIImageimagenamed:@"Pushu.jpg"];UIImage*waterimage = [ SelfWatermarkimage:image withtext:@"Park Tree watermark Test"]; Uiimagewritetosavedphotosalbum (Waterimage,Nil,Nil,Nil);//Save pictures to albums//Show Pictures Uiimageview*imageview = [[UiimageviewAlloc] initWithFrame: Self. View. Bounds]; ImageView. Image= Waterimage; [ Self. ViewAddsubview:imageview];additional setup after loading the view, typically from a nib.}
-(UIImage*)Watermarkimage: (UIImage*)ImageWithtext: (nsstring*)text{Uigraphicsbeginimagecontext (Image.size);//Draw content in the canvas[ImageDrawinrect:cgrectmake (0,0,Image.size. width,Image.size. height)];//Draw text[[Uicolor Darkgraycolor] set]; CGRect rect = CGRectMake ( -, -, $, -); Nsdictionary*dic= @{nsfontattributename:[uifont Systemfontofsize: -], Nsobliquenessattributename:@1};//Here Set the font, and tilt. Specific article links at the end of other reference articles[textDrawinrect:rect Withattributes:dic];//Before iOS7, it is more convenient to use the following methods//[text Drawinrect:rect withfont:[uifont systemfontofsize:30] linebreakmode:nslinebreakbywordwrapping alignment : Nstextalignmentcenter];//Get an image from the canvasUIImage*returnimage= Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext ();returnReturnimage;}
- (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs NS_AVAILABLE_IOS(7_0);
About this method, which is applied after iOS7. Attrs the specific instructions for setting the parameters in the following link article:
Description Article Link: attrs reference article
iOS image plus watermark effect and save to albums