Set UIImage Fillet
@interface UIImage (Uiroundedrectimage)
+ (ID) createroundedrectimage: (uiimage*) Image size: (cgsize) size;
@end
@implementation UIImage (Uiroundedrectimage)
static void Addroundedrecttopath (Cgcontextref context, CGRect rect, float ovalwidth,
float ovalheight)
{
float FW,FH;
if (Ovalwidth = = 0 | | ovalheight = = 0) {
Cgcontextaddrect (context, rect);
Return
}
Cgcontextsavegstate (context);
CGCONTEXTTRANSLATECTM (Context, Cgrectgetminx (rect), Cgrectgetminy (rect));
CGCONTEXTSCALECTM (context, ovalwidth, ovalheight);
FW = Cgrectgetwidth (rect)/ovalwidth;
FH = cgrectgetheight (rect)/ovalheight;
Cgcontextmovetopoint (Context, FW, FH/2); Start at lower right corner
Cgcontextaddarctopoint (context, FW, FH, FW/2, FH, 1); Top right Corner
Cgcontextaddarctopoint (context, 0, FH, 0, FH/2, 1); Top left corner
Cgcontextaddarctopoint (context, 0, 0, FW/2, 0, 1); Lower left corner
Cgcontextaddarctopoint (context, FW, 0, FW, FH/2, 1); Back to lower right
Cgcontextclosepath (context);
Cgcontextrestoregstate (context);
}
+ (ID) createroundedrectimage: (uiimage*) Image size: (cgsize) size
{
The size of Cgcontextref
int w = size.width;
int h = size.height;
UIImage *img = image;
Cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb ();
Cgcontextref context = Cgbitmapcontextcreate (NULL, W, H, 8, 4 * W, Colorspace,kcgimagealphapremultipliedfirst);
CGRect rect = CGRectMake (0, 0, W, h);
Cgcontextbeginpath (context);
Addroundedrecttopath (Context, Rect, 5, 5);
Cgcontextclosepath (context);
Cgcontextclip (context);
Cgcontextdrawimage (context, CGRectMake (0, 0, W, h), IMG. Cgimage);
Cgimageref imagemasked = cgbitmapcontextcreateimage (context);
Cgcontextrelease (context);
Cgcolorspacerelease (ColorSpace);
return [UIImage imagewithcgimage:imagemasked];
}
@end
Set UIImage Fillet