0
私は次のコードを使用してタッチイベントで画像を色づけしています。私はサブクラスのuiviewを持っており、それを行うために次のコードを使用しています。それは働いていますが、色はimages.supposeの異なる部分で異なります。緑色、黄色、または他の色の画像の異なる部分に存在する。赤色は、画像内にすでに存在する色に基づいて異なる効果を有する。その代わりに、画像全体に同じ赤色(または選択された色)が必要である。どうすればそれを達成できますか?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がの背景色に画像を設定している着色された効果を与えたいではありませんcolorwithpatternimageを使用してuiview – Bhoomi
これをやりたい場合、簡単な方法は、UIImageの上に透明なUIviewを追加し、ユーザーに描画させることです。描画が完了すると、ビューのスナップショットを撮り、そこから新しいイメージを作成することができます。 – Vignesh
uiimageviewの上に透明なuiviewを追加している場合はuiimageを含んでいますが、同様の色は透明なだけですuiview.uiimageは見えません – Bhoomi