Add watermarks or text to IOS images

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 = margin (); // create a graphic context with cgbitmapcontextcreate cgcontextref context = cgbitmapcontextcreate (null, W, h, 8, 4 * w, colorspace, limit ); cgcontextdrawimage (context, cgrectmake (0, 0, W, h), IMG. cgimage); cgcontextsetrgbfillcolor (context, 0.0, 1.0, 1.0, 1); char * text = (char *) [text1 cstringusingencoding: nsasistringencoding]; cgcontextselectfont (context, "Georgia ", 30, kcgencodingmacroman); cgcontextsettextdrawingmode (context, kcgtextfill); gradient (context, 255, 0, 0, 1); cgcontextshowtextatpoint (context, W/2-strlen (text) * 5, h/2, text, strlen (text); // Create Image ref from the context cgimageref imagemasked = cgbitmapcontextcreateimage (context); cgcontextrelease (context); cgcolorspacerelspace (colorspace ); return [uiimage imagewithcgimage: imagemasked];}

 

2. Add Images

-(Uiimage *) addimagelogo :( uiimage *) IMG text :( uiimage *) Logo {// 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 = margin (); // create a graphic context with cgbitmapcontextcreate cgcontextref context = cgbitmapcontextcreate (null, W, h, 8, 4 * w, colorspace, limit ); cgcontextdrawimage (context, cgrectmake (0, 0, W, h), IMG. cgimage); cgcontextdrawimage (context, cgrectmake (W-logowidth, 0, logowidth, logoheight), [logo cgimage]); cgimageref imagemasked = background (context); cgcontextrelease (context ); cgcolorspacerelease (colorspace); return [uiimage imagewithcgimage: imagemasked]; // cgcontextdrawimage (contextref, cgrectmake (100, 50,200, 80), [smallimg cgimage]);}

 

 

 

3. Add a 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. A height-addImage1.size.height, addimage1.size. width, addimage1.size. height)]; uiimage * resultingimage = uigraphicsgetimagefromcurrentimagecontext (); uigraphicsendimagecontext (); Return resultingimage ;}
Http://hi.baidu.com/peter_wwj/item/179cbe060c570e873c42e298
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.