Image add watermark Effect

Source: Internet
Author: User

  1. Create a UIImage object
  2. UIImage *image = [UIImage imagenamed:@ "scene1.jpg"];
  3. 1. Establish Bitmap Context
  4. Uigraphicsbeginimagecontext (image.size);
  5. 2. Draw the original image to the context
  6. [Image drawinrect:cgrectmake (0, 0, Image.size.width, image.size.height)];
  7. 3. Draw the watermark text to the context.
  8. Watermark in lower left corner
  9. CGRect textFrame = CGRectMake (0, image.size.height-40, 200, 40);
  10. Set Watermark Text Properties
  11. Uifont *font = [Uifont boldsystemfontofsize:30];
  12. Nsmutableparagraphstyle *style = [[Nsmutableparagraphstyle alloc] init];
  13. Style.alignment = Nstextalignmentcenter;
  14. Uicolor *color = [Uicolor colorwithred:254.0/255 green:201.0/255 blue:21.0/255 alpha:1];
  15. [Text Drawinrect:textframe withattributes:
  16. @{nsfontattributename:font,
  17. Nsforegroundcolorattributename:color,
  18. Nsparagraphstyleattributename:style}];
  19. 4. From the bitmap context to obtain a watermark after the picture.
  20. UIImage *waterimage = Uigraphicsgetimagefromcurrentimagecontext ();
  21. 5. Close Bitmap context.
  22. Uigraphicsendimagecontext ();
  23. 6. Return the captured picture
  24. return waterimage;
  25. This method is best to be independent of a single class, which can be done with just one type of method.

Image add watermark Effect

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.