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, Kcgimagealphapremultipliedfirst);
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
{
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 (), [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.height-addimage1.size.height, AddImage1.size.width, AddImage1.size.height)];
UIImage *resultingimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return resultingimage;}
Add text and watermarks