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, 10, 10 );
Cgcontextclosepath (context );
Cgcontextclip (context );
Cgcontextdrawimage (context, cgrectmake (0, 0, W, h), IMG. cgimage );
Cgimageref imagemasked = cgbitmapcontextcreateimage (context );
Cgcontextrelease (context );
Cgcolorspacerelstrap (colorspace );
Return [uiimage imagewithcgimage: imagemasked];
}
Directly call createroundedrectimage ....
Returns the rounded corner image.
Modify cgcontextaddarctopoint on the rounded corner ....