Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-16-2009, 09:25 PM   #1 (permalink)
john855
Registered Member
 
Join Date: Nov 2008
Posts: 148
john855 is on a distinguished road
Default Quartz border (1 pixel border around an image)

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;
}
john855 is offline   Reply With Quote
 

» Advertisements
» Online Users: 573
14 members and 559 guests
AppleDev, blanix, blasterbr, Domele, G-Power, GarryTheGarlic, iekei, ITCreative, mediaspree, ncc1701e, nt.hai, OgreSwamp, Penicillin, tranvutuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 174,548
Threads: 93,727
Posts: 401,266
Top Poster: BrianSlick (7,954)
Welcome to our newest member, rosalvadx91
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:18 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.