美文网首页
图片添加水印

图片添加水印

作者: 飘金 | 来源:发表于2017-04-25 17:06 被阅读0次

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

}

}

相关文章

网友评论

      本文标题:图片添加水印

      本文链接:https://www.haomeiwen.com/subject/gqnvzttx.html