iOS plus watermark

Source: Internet
Author: User

1. Add text

 -(UIImage *) AddText: (UIImage *) img Text: (NSString *) text1 {          //get image Width and height          int w = img.size.width;         int h = img.size.height;         cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb ();         //create a graphic context with cgbitmapcontextcreate          cgcontextref context = Cgbitmapcontextcreate (NULL, W, H, 8, 4 * W, ColorSpace, KCGIma Gealphapremultipliedfirst);        cgcontextdrawimage (context, CGRectMake (0, 0, W, h), IMG. Cgimage);         cgcontextsetrgbfillcolor (context, 0.0, 1.0, 1.0, 1);         char* Text = (char *) [Text1 cstringusingencoding:nsasciistringencodING];         cgcontextselectfont (Context, "Georgia", Kcgencodingmacroman);         cgcontextsettextdrawingmode (context, KCGTextFill);         cgcontextsetrgbfillcolor (context, 255, 0, 0, 1);         cgcontextshowtextatpoint (Context, W/2-strlen (text), H/2, text, strlen (text));         //create image ref from the context          cgimageref imagemasked = cgbitmapcontextcreateimage (context);         cgcontextrelease (context);         cgcolorspacerelease (ColorSpace);         return [UIImage imagewithcgimage:imagemasked]; } 2. Add Picture-(UIImage *) Addimagelogo: (UIImage *) img Text: (UIImage *) logo {    &NBsp;  //get image Width and height         int w = img.size.width;         int h = img.size.height;        int logowidth = logo.size.width;         int logoheight = logo.size.height;         cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb ();               //create a graphic context With cgbitmapcontextcreate         cgcontextref context = Cgbitmapcontextcreate (NULL, W, H, 8, 4 * W, colorspace, Kcgimagealphapremultipliedfirst);         cgcontextdrawimage (context, CGRectMake (0, 0, W, h), IMG. Cgimage);         cgcontextdrawimage (Context, CGRectMake (w-logoWidth, 0, LogoWidth, logoheight), [logo cgimage]);         cgimageref imagemasked = cgbitmapcontextcreateimage (context);         cgcontextrelease (context);         cgcolorspacerelease (ColorSpace);         return [UIImage imagewithcgimage:imagemasked];         // cgcontextdrawimage (Contextref, CGRectMake (100, 50, 200, 80 ), [smallimg cgimage]);  } 3. Plus Translucent Watermark-(UIImage *) AddImage: (UIImage *) useimage addImage1: (UIImage *) addImage1 {          uigraphicsbeginimagecontext (useImage.size);                 [useimage DrawInRect: CGRectMake (0, 0, UseImage.size.width, useImage.size.height)];              [addimage1 DrawInRect:CGRectMake ( 0, USeimage.size.height-addimage1.size.height, AddImage1.size.width, AddImage1.size.height)];             uiimage *resultingImage = Uigraphicsgetimagefromcurrentimagecontext ();          uigraphicsendimagecontext ();               return ResultingImage;   }

iOS plus watermark

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.