图片添加水印

- (UIImage*) imageWithWaterMask:(UIImage*)mask inRect:(CGRect)rect location:(UIImage*)location locationRect:(CGRect)locationRect WithStringWaterMark:(NSString*)markString atPoint:(CGPoint)point attr:(NSDictionary*)attr city:(NSString*)city atPoint:(CGPoint)cityPoint cityAttr:(NSDictionary*)cityAttr

{

if(!mask && !location){

returnnil;

}else{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >=40000

if([[[UIDevicecurrentDevice]systemVersion]floatValue] >=4.0)

{

UIGraphicsBeginImageContextWithOptions([selfsize],NO,0.0);// 0.0 for scale means "scale for device's main screen".

}

#else

if([[[UIDevice currentDevice] systemVersion] floatValue] <4.0)

{

UIGraphicsBeginImageContext([selfsize]);

}

#endif

//原图

[selfdrawInRect:CGRectMake(0,0,self.size.width,self.size.height)];

//水印图

if(mask){

[maskdrawInRect:rect];

}

if(location){

[locationdrawInRect:locationRect];

}

//水印文字

if(![NSStringToolisBlankString:markString]){

[markStringdrawAtPoint:pointwithAttributes:attr];

}

if(![NSStringToolisBlankString:city]){

[citydrawAtPoint:cityPointwithAttributes:cityAttr];

}

UIImage*newPic =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

returnnewPic;

}

}

你可能感兴趣的:(图片添加水印)