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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2009, 10:25 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 148
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
Old 03-09-2010, 04:29 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 148
Default

anyone?
john855 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 278
22 members and 256 guests
ADY, Bertrand21, Dani77, fkmtc, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0