iOS 图片添加水印

释放双眼,带上耳机,听听看~!

-(UIImage *)aspjpegImage:(UIImage *)img withWord:(NSString *)word
{
NSString* mark = word;
int w = img.size.width;
int h = img.size.height;
//UIGraphicsBeginImageContext创建一个基于位图的上下文(context),并将其设置为当前上下文(context)
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0, 0, w, h)];
NSDictionary *attr = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:20],   //设置字体
NSForegroundColorAttributeName : [UIColor redColor]      //设置字体颜色
};
//文本绘制 attr代表文本属性
[mark drawInRect:CGRectMake(0, 10, 100, 50) withAttributes:attr];                 //左上角
[mark drawInRect:CGRectMake(w - 200, 10, 200, 50) withAttributes:attr];            //右上角
[mark drawInRect:CGRectMake(w - 200, h - 50 - 10, 200, 50) withAttributes:attr];   //右下角
[mark drawInRect:CGRectMake(0, h - 50 - 10, 200, 50) withAttributes:attr];        //左下角
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImg;
}
//使用
UIImage * syImage=   [self  aspjpegImage:image withWord:@"@哈哈同学"];

人已赞赏
iOS文章

iOS GCD-信号量(semaphore)

2020-3-2 18:59:18

iOS文章

ios 在view中创建通知 移除通知

2020-3-2 22:01:20

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索