Add watermarks for iOS photos and for iOS photos

Source: Internet
Author: User

Add watermarks for iOS photos and for iOS photos

During the project, we need to mark the photos to prevent image theft by others. Therefore, we need to add a watermark to the photo to indicate its uniqueness.

Adding a watermark is not to add several labels on it, but to draw the text into a whole.

Provide a method. This method only needs to pass the image and the content of the watermark to achieve the effect.

1-(UIImage *) watermarkImage :( UIImage *) img withName :( NSString *) name 2 3 {4 5 NSString * mark = name; 6 7 int w = img. size. width; 8 9 int h = img. size. height; 10 11 UIGraphicsBeginImageContext (img. size); 12 13 [img drawInRect: CGRectMake (0, 0, w, h)]; 14 15 NSDictionary * attr =@{ 16 17 NSFontAttributeName: [UIFont boldSystemFontOfSize: 20], // set the font 18 19 NSForegroundColorAttributeName: [UIColor redColor] // set the font color 20 21}; 22 23 [mark drawInRect: CGRectMake (0, 10, 80, 32) withAttributes: attr]; // 24 25 [mark drawInRect: CGRectMake (w-80, 10, 80, 32) withAttributes: attr]; // 26 27 [mark drawInRect: CGRectMake (w-80, h-32-10, 80, 32) withAttributes: attr]; // 28 29 in the lower right corner [mark drawInRect: CGRectMake (0, h-32-10, 80, 32) withAttributes: attr]; // 30 31 UIImage * aimg = UIGraphicsGetImageFromCurrentImageContext (); 32 33 UIGraphicsEndImageContext (); 34 35 return aimg; 36}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.