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

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

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-15-2010, 02:45 AM   #15 (permalink)
RegisteredJustForThi
Registered Member
 
Join Date: Sep 2010
Posts: 3
RegisteredJustForThi is on a distinguished road
Default Better late than never

This thread helped me solve a problem in the application I am currently developing. I have a more efficient solution thanks to you guys. I'm sure it's too late to be useful for anyone in this thread but it may be helpful to other people in the future. Part of my application is a drawing canvas w/ any number of backgrounds that can be loaded, including plain colors, notepaper, images, pdf's, etc. I have a layer over the top of the background that all of the drawing gets done on. Now thanks to this thread I am using

CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);

for all the drawing. The drawing is fairly standard code that goes like this:

//------------------------------------------------------------------------

pCoordY = [[previousArray objectAtIndex:2] floatValue];
pCoordX = [[previousArray objectAtIndex:1] floatValue];
nCoordY = [[currentArray objectAtIndex:2] floatValue];
nCoordX = [[currentArray objectAtIndex:1] floatValue];

UIGraphicsBeginImageContext(self.view.frame.size);

[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeNormal);

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentCon text(), redColor, greenColor, blueColor, alphaColor);

CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext() , pCoordX, pCoordY);
CGContextAddLineToPoint(UIGraphicsGetCurrentContex t(), nCoordX, nCoordY);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;

drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//-----------------------------------------------------------------------


To make a circular eraser tool, you need only make two changes:

From:
CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeNormal);
To:
CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);

And:

From:
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentCon text(), redColor, greenColor, blueColor, alphaColor);
To:
CGContextSetStrokeColorWithColor(UIGraphicsGetCurr entContext(), [UIColor clearColor].CGColor);


I'm sure everybody's app has some particulars so that copy/pasting this code will be difficult. But just the same this is how I accomplished it and it works fabulously well for my app.

Best of luck!
RegisteredJustForThi is offline   Reply With Quote
 

» Advertisements
» Online Users: 398
15 members and 383 guests
alexdesuja, chemistry, Chickenrig, dansparrow, EvilElf, hrushikeshaddon, iconomania, ipodphone, jimmyon122, larhondaxzcw, linkmx, Mnadeep, SamorodovAlex, tomtom100, zhaoningmei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,585
Threads: 94,083
Posts: 402,775
Top Poster: BrianSlick (7,990)
Welcome to our newest member, alexdesuja
Powered by vBadvanced CMPS v3.1.0

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