0
我正在使用以下代碼在觸摸event.I具有子類uiview,並使用下面的代碼來做到這一點。它是工作,但不同的部分圖像上的顏色是不同的。因爲我用紅色着色圖像,有綠色,黃色或其他顏色出現在圖像的不同部分。然後紅色根據圖像中已經存在的顏色而具有不同的效果。替代地,我想要在整個圖像中填充相同的紅色(或者選擇的任何顏色)。我怎麼能做到這一點?如何彩色圖像無論iphone中的圖像中呈現的顏色?
@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];
}
當我使用kCGBlendModeCopy和一些其他的色彩效果是整個image.but圖像上同樣不visible.i想給該用戶的着色image.i已設置圖像的背景顏色效果uiview使用colorwithpatternimage – Bhoomi 2012-04-24 04:42:00
如果你想這樣做,簡單的方法是在UIImage上添加一個透明的UIview並讓用戶繪製。一旦完成繪圖,您可以拍攝視圖快照並從中創建新圖像。 – Vignesh 2012-04-24 04:45:07
如果我在其中包含uiimage的uiimageview之上添加透明uiview,那麼效果也是類似的顏色只在透明uiview.uiimage不可見 – Bhoomi 2012-04-24 05:06:30