I am trying to use quartz 2d to draw a simple path around an image. It is a rectangle with rounded corners, and I haven't been able to get this to work using the same function that is rounding off the corners of my image but for the life of me I cant get it to work.
Here is my effort so far (which does not work):
Code:
+(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight
{
UIImage * newImage = nil;
if( nil != img)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextBeginPath(context);
CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
CGContextClosePath(context);
CGContextClip(context);
/*
CGRect rect2 = CGRectMake(0, 0, img.size.width-10, img.size.height-10);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 10);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextStrokeRect(context, rect2);
CGContextClosePath(context);
*/
//add a border
/*
CGContextBeginPath(context);
addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
CGContextSetLineWidth(context, 10);
CGContextStrokePath(context);
CGContextClosePath(context);
*/
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
newImage = [[UIImage imageWithCGImage:imageMasked] retain];
[ pool release];
}
return newImage;
}