У меня есть изображение на моем виде, и я рисую на изображении цветами, как в коде ниже:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2)
{
//imageDraw.image = nil;
return;
}
else
{
}
lastPoint = [touch locationInView:imageDraw];
lastPoint.y -= 5;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:mView];
currentPoint.y -= 5;
UIGraphicsBeginImageContext(imageDraw.frame.size);
[imageDraw.image drawInRect:CGRectMake(0, 0, imageDraw.frame.size.width, imageDraw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 0.5);
DrawAppDelegate *appDelegate=(DrawAppDelegate*)[ [UIApplication sharedApplication] delegate];
UIColor *clr = appDelegate.txtColor;
[clr setStroke];
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageDraw.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10)
{
mouseMoved = 0;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
DrawAppDelegate *appDelegate=(DrawAppDelegate*)[ [UIApplication sharedApplication] delegate];
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2)
{
//imageDraw.image = nil;
return;
}
else
{
}
if(!mouseSwiped)
{
UIGraphicsBeginImageContext(imageDraw.frame.size);
[imageDraw.image drawInRect:CGRectMake(0, 0, imageDraw.frame.size.width, imageDraw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
UIColor *clr = appDelegate.txtColor;
[clr setStroke];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
imageDraw.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
-(void)drawText
{
/*TextViewController *viewController = [[TextViewController alloc]init];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
*/
colorWheel = [[ColorPickerImageView alloc] initWithFrame:CGRectMake(20,20,300,340)];
[colorWheel setImage:[UIImage imageNamed:@"colorWheel1.png"]];
[colorWheel setUserInteractionEnabled:YES];
colorWheel.backgroundColor = [UIColor clearColor];
colorWheel.pickedColorDelegate = self;
[mView addSubview:colorWheel];
[self animateColorWheelToShow:YES duration:0.3];
}
- (void) pickedColor:(UIColor*)color
{
//mView.backgroundColor= color;
DrawAppDelegate *appDelegate=(DrawAppDelegate*)[ [UIApplication sharedApplication] delegate];
[self animateColorWheelToShow:NO duration:0.3];
appDelegate.txtColor = color;
//[self setNeedsDisplayInRect:CGRectMake(0, 0, 320, 480)];
[mView setNeedsDisplay];
}
Теперь я хочу стереть какой-нибудь нарисованный цвет на изображении. Может ли кто-нибудь подсказать мне, как я могу сделать какие-либо идеи, пожалуйста, с некоторым примером кода.
Любая помощь будет глубоко признательна.
Спасибо всем,
Мониш.