iOS水印的简单实现

- (void)watermark {

    UIImage *oldImage = [UIImage imageNamed:@"事先准备好的图片,你将要在这帐图片上添加水印"];

    

    UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);

    [oldImage drawInRect:CGRectMake(0, 0, oldImage.size.width, oldImage.size.height)];

    

    UIImage *waterImage = [UIImage imageNamed:@"这是您将要在事先准备好的图片上放置的logo"];

    CGFloat waterW = 50;

    CGFloat waterH = 25;

    CGFloat waterX = oldImage.size.width - waterW - 5;

    CGFloat waterY = oldImage.size.height - waterH - 5;

    CGRect waterRect = CGRectMake(waterX, waterY, waterW, waterH);

    [waterImage drawInRect:waterRect];

    

    //得到最终的图片

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    self.imageView.image = newImage;

    

    

    NSData *data = UIImagePNGRepresentation(newImage);

    [data writeToFile:@"将弄好的图片保存到的文件路径/图片名.png" atomically:YES];

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。