I am using following code to color image on touch event.I have subclass uiview and using following code to do that.It is working but color is different on different part of images.suppose i am coloring image with red color and there are green,yellow or other colors present in different part of images.then red color have different effects based on the color already present in image.Instead of that i want same red color(or whatever color selected) to be filled in the entire image.How can i achieve that?
@synthesize selImage,isReset;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
arrBezierPaths = [[NSMutableArray alloc] init];
globalPath = [[UIBezierPath alloc] init];
myPath = [[UIBezierPath alloc] init];
self.userInteractionEnabled = TRUE;
myPath.lineWidth = 30;
brushPattern = [UIColor redColor];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:myPath, @"Path", brushPattern, @"Color", nil];
[arrBezierPaths addObject:dict];
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
for (int i=0; i<[arrBezierPaths count]; i++)
{
NSDictionary *dict = [arrBezierPaths objectAtIndex:i];
UIColor *tempBrushpatter = [[UIColor alloc] init];
tempBrushpatter = [dict valueForKey:@"Color"];
globalPath = [dict valueForKey:@"Path"];
[globalPath strokeWithBlendMode:kCGBlendModeOverlay alpha:1.0];
[tempBrushpatter setStroke];
}
}
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
[globalPath moveToPoint:[mytouch locationInView:self]];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
CGPoint pointTouched = [mytouch locationInView:self];
for (int i=0; i<[arrBezierPaths count]; i++)
{
UIBezierPath *tempErasePath = [[UIBezierPath alloc] init];
NSDictionary *dictTemp = [arrBezierPaths objectAtIndex:0];
UIBezierPath *temppath = [dictTemp valueForKey:@"Path"];
if ([temppath containsPoint:pointTouched])
{
//[temppath removeAllPoints];
}
}
[globalPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void)changeColor:(UIColor *)color
{
[arrRemovePaths removeAllObjects];
UIBezierPath *temp = [[UIBezierPath alloc] init];
temp.lineWidth = 30;
UIColor *brushColor = color;
NSLog(@"initWithFrame method called");
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:temp, @"Path", brushColor, @"Color", nil];
[temp release];
[arrBezierPaths addObject:dict];
brushPattern = [color retain];
[self setNeedsDisplay];
}
- (void)dealloc
{
// [brushPattern release];
[super dealloc];
}
try replacing the line
[globalPath strokeWithBlendMode:kCGBlendModeOverlay alpha:1.0];withIf you want to how the different blend mode works look here(Figure 2-1).