iOS - Quartz2D图片水印

作者:Mitchell 

  • 1、获取图片
    UIImage*image = [UIImage imageNamed:@"imageName"];
  • 2、获取位图上下文
    UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
  • 3、绘制图片
    [image drawAtPoint:CGPointMake(0, 0)];
  • 4、绘制文字
    NSString*str = @"Mitchell";
    [str drawAtPoint:CGPointMake(10, 10) withAttributes:@{NSForegroundColorAttributeName:[UIColor magentaColor],NSFontAttributeName:[UIFont systemFontOfSize:40]}];
  • 5、生成图片
    image = UIGraphicsGetImageFromCurrentImageContext();
  • 6、关闭上下文
    UIGraphicsEndImageContext();
  • 7、获取图片数据
    NSData *data = UIImagePNGRepresentation(image);
  • 8、保存图片
    _img = [UIImage imageWithData:data];

你可能感兴趣的:(iOS - Quartz2D图片水印)