【发布时间】:2013-08-12 16:24:35
【问题描述】:
我已经尝试和搜索了很多,但没有找到解决方案。
我将这张图片保存为 .png [1]:http://imm.io/1f3DY
如果用户触摸 f.e.在区域 1
我想用颜色 f.e. 填充这个区域。蓝色。
有没有办法在代码中找出/创建这些区域并用颜色填充?
我已将我的 .png 转换为 .svg 并创建了一些 bezierpathes。将贝塞尔路径存储在一个数组中并添加一个手势识别器。这工作正常。得到了我所触及的正确道路。可以改变路径的颜色。但只有黑线。我想填补 f.e. 之间的空间。 path1 和 path 2。我该怎么做?
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
location.y = self.view.bounds.size.height - location.y;
for(int i = 0; i< bezierPathes.count; i++)
{
//if([b containsPoint:location])
UIBezierPath* b = bezierPathes[i];
if([[self tapTargetForPath:b] containsPoint:location])
{
[[UIColor redColor] setFill];
[b fill];
[testView setNeedsDisplay];
}
}
}
// this method will let you easily select a bezier path ( 15 px up and down of a path drawing)
- (UIBezierPath *)tapTargetForPath:(UIBezierPath *)path
{
if (path == nil) {
return nil;
}
CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(path.CGPath, NULL, fmaxf(35.0f, path.lineWidth), path.lineCapStyle, path.lineJoinStyle, path.miterLimit);
if (tapTargetPath == NULL) {
return nil;
}
UIBezierPath *tapTarget = [UIBezierPath bezierPathWithCGPath:tapTargetPath];
CGPathRelease(tapTargetPath);
return tapTarget;
}
【问题讨论】:
-
如果您只有一张图像(jpg、png 等),您将不得不使用边缘检测算法,因为您无法从图像中获得想要填充的区域。或者,您可以为要填充的每个形状定义一些坐标,然后使用核心图形。
标签: ios objective-c colors