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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-04-2010, 10:17 PM   #1 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default drawing app - eraser as a circle

hello!
In my drawing app, this line of code makes an "eraser"

Code:
CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
the problem is that the "eraser" is a square...

I tried to make it a circle by rotating that "square" eraser about a lot of times with an arc4random code for a circle like appearence because a bunch of turned squares makes a circle.

Code:
CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
the only problem is that the square is not rotating around where my finger is "currentPosition X and Y" it rotates around random spots and seems to jump everywhere!

any help?

thanks!
orange gold is offline   Reply With Quote
Old 04-04-2010, 10:35 PM   #2 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

If i translate the turned square back to my finger coordinates...

Code:
CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x - 12.5, currentPoint.y - 12.5);
		CGRect circleRect = CGRectMake(currentPoint.x - 12.5, currentPoint.y - 12.5, 25, 25); 
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
It is no longer turned

Anyone?
orange gold is offline   Reply With Quote
Old 04-04-2010, 11:14 PM   #3 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

tried a different approach.

turned my CGRect "square" into a "circle"

now the problem is the "eraser" is still only a square then there is a black circle circumscribing it.

So i try to change the fill color and stroke color of the circle to clear... no luck?

Code:
CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
		CGContextStrokeEllipseInRect(UIGraphicsGetCurrentContext(),circleRect);
		CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
orange gold is offline   Reply With Quote
Old 04-05-2010, 01:44 AM   #4 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

bump
orange gold is offline   Reply With Quote
Old 04-05-2010, 04:49 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 267
georgeburns is on a distinguished road
Default

Not too familiar with this stuff... but can't you just CGContextStrokeEllipseInRect with a clear color and be done with it?
georgeburns is offline   Reply With Quote
Old 04-05-2010, 11:51 AM   #6 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

look at my post right before yours, I did try that and it did not work., thanks though
orange gold is offline   Reply With Quote
Old 04-05-2010, 01:22 PM   #7 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

okay I almost have figured it out...

this line of code
CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
to rotate the eraser is rotating it, but its also putting the eraser on a point on the edge of a circle thats center is the top left corner of the iPhone screen.

ex.

circle's center = top left corner of iPhone screen
radius = distance from my finger to center
and the eraser is turning but also being put on a random point on the edge of the circle, If I move my finger up to the top left corner of the screen it rotates and doesnt fly every where because it is in the center, how can I make the center of that "circle" my finger
I'm assuming I need to translate the center to be where my fingers are... any ideas?
orange gold is offline   Reply With Quote
Old 04-05-2010, 01:44 PM   #8 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

this doesnt work either...

trying to move the top left corner of my imageview im drawing on to where my finger is, then moving it back after each new drawing is placed...

Code:
xcenter = drawImage.center.x;
		ycenter = drawImage.center.y;
		drawImage.center = CGPointMake (currentPoint.x - xcenter, currentPoint.y - ycenter);
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);// now it makes my rotation happen at 250X and 250Y but only when my finger is at 0X, 0Y ???
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		//CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
		CGContextBeginPath(UIGraphicsGetCurrentContext());
		CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
		CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
		CGContextStrokePath(UIGraphicsGetCurrentContext());
		drawImage.center = CGPointMake (xcenter, ycenter);
orange gold is offline   Reply With Quote
Old 04-05-2010, 04:43 PM   #9 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

solved it, you just translate it to 0,0 rotate it, then translate it back

Code:
CGRect circleRect = CGRectMake(currentPoint.x - 12.5, currentPoint.y - 12.5, 25, 25);
CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
and to stack multiple turned squares for a circle eraser appearance i just repeat the code... simple copy and paste!

Code:
		CGRect circleRect = CGRectMake(currentPoint.x - 12.5, currentPoint.y - 12.5, 25, 25);
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		//below repeats code with a dif. spin so that we get a circle eraser not a square eraser... many stacked and rotated squares = circle!
		//squares released later to save memory and stop from overload.
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		//bad code below//
		
		
		//CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
		//CGContextFillEllipseInRect (UIGraphicsGetCurrentContext(),  circleRect);
		//CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
		//CGContextStrokeEllipseInRect(UIGraphicsGetCurrentContext(),circleRect);
		//CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		/*
		
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		 */
		/*
		
		//CGPoint center = CGPointMake(circleRect.size.height/2.0, circleRect.size.width/2.0);
		//CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		//CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x, -currentPoint.y);
		//CGContextMoveToPoint(UIGraphicsGetCurrentContext(), center.x, center.y);
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), 0, 0);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x, -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		 */
		
		//end eraser//

Last edited by orange gold; 04-05-2010 at 04:53 PM.
orange gold is offline   Reply With Quote
Old 04-06-2010, 01:20 AM   #10 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 267
georgeburns is on a distinguished road
Default

Quote:
Originally Posted by orange gold View Post
look at my post right before yours, I did try that and it did not work., thanks though
Ya... you did and then you followed it with a
CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
Which would be the square... I was saying try it without that part.
georgeburns is offline   Reply With Quote
Old 04-06-2010, 06:27 AM   #11 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

orange gold,
i am also looking to do this.. haven't got time to study it though..

but IMO that code is just too long to do a simple thing. i think there is an easier way. i'll share here if i find it.
rocotilos is offline   Reply With Quote
Old 04-06-2010, 08:51 PM   #12 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

thanks dude but to be honest I really cant find anything simpler, anyways the code isnt that long, all I did was copy and paste the 4 lines of code over and over after that to make a bunch of turned squares I'm sure you could do it with variables and arrays...

but I dont really care about the length of code, I'm just glad that it works and it is not laggy, also depending on the size of the eraser you have to copy and paste it more times, and if the eraser is smaller then like 23 it seems to leave a hole in the middle so you might need to translate it...

anyways I'm just glad I can finish my app now

Last edited by orange gold; 04-06-2010 at 08:53 PM.
orange gold is offline   Reply With Quote
Old 04-06-2010, 10:38 PM   #13 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 686
orange gold is an unknown quantity at this point
Default

Quote:
Originally Posted by rocotilos View Post
.
ahha, I cant stop laughing at emirbytes ahha
reminds me of emirducks

also I replied to your comment above --------------^
orange gold is offline   Reply With Quote
Old 08-18-2010, 05:03 AM   #14 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 4
BaconWang is on a distinguished road
Default help

Quote:
Originally Posted by orange gold View Post
solved it, you just translate it to 0,0 rotate it, then translate it back



and to stack multiple turned squares for a circle eraser appearance i just repeat the code... simple copy and paste!

Code:
		CGRect circleRect = CGRectMake(currentPoint.x - 12.5, currentPoint.y - 12.5, 25, 25);
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		//below repeats code with a dif. spin so that we get a circle eraser not a square eraser... many stacked and rotated squares = circle!
		//squares released later to save memory and stop from overload.
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), +currentPoint.x , +currentPoint.y);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), -currentPoint.x , -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		//bad code below//
		
		
		//CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
		//CGContextFillEllipseInRect (UIGraphicsGetCurrentContext(),  circleRect);
		//CGRect circleRect = CGRectMake(currentPoint.x-12.5, currentPoint.y-12.5, 25, 25); 
		//CGContextStrokeEllipseInRect(UIGraphicsGetCurrentContext(),circleRect);
		//CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
		//CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		/*
		
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random());
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		 */
		/*
		
		//CGPoint center = CGPointMake(circleRect.size.height/2.0, circleRect.size.width/2.0);
		//CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		//CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x, -currentPoint.y);
		//CGContextMoveToPoint(UIGraphicsGetCurrentContext(), center.x, center.y);
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), 0, 0);
		CGContextRotateCTM (UIGraphicsGetCurrentContext(), arc4random()); //rotates around upper left corner of iPhone.
		CGContextTranslateCTM (UIGraphicsGetCurrentContext(), currentPoint.x, -currentPoint.y);
		CGContextClearRect(UIGraphicsGetCurrentContext(), circleRect);
		 */
		
		//end eraser//
this way is solved it but speed is too slower ,how solved ?
BaconWang is offline   Reply With Quote
Old 09-15-2010, 02:45 AM   #15 (permalink)
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
Old 11-06-2011, 10:37 AM   #16 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 35
rijeka2008 is on a distinguished road
Default

Thanks for the code!
rijeka2008 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: 313
8 members and 305 guests
chemistry, Fstuff, heshiming, iAppDeveloper, jbro, kapps11, SLIC, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,872
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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