2013-05-06 91 views
2

我需要創建一個應用程序,就像Windows中的Paint應用程序一樣。請在此鏈接如何檢測iOS中的封閉區域並在其中填充顏色?

https://dl.dropboxusercontent.com/u/56721867/Screen%20Recording.mov

檢查出的視頻這是我需要我的應用程序進行工作。 我可以通過使用UIBezierPathCGContext類來繪製線條和填充顏色,但是如何通過在視頻中顯示的內部點擊內容來填充封閉區域內的顏色。請讓我知道這個方法,以及iOS中的哪個課程可以實現這一點。 謝謝!

回答

1

我們有一個UIBezierPath財產containsPoint:

添加以下代碼- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

if ([aPath containsPoint:touchloc1]) { 
//then set a flag value. 
      } 

而且在- (void)drawRect:(CGRect)rect方法添加以下代碼

if (flag){ 
    [[UIColor redColor] setFill]; 
    [yourPath fill]; 
} 
else{ 
//Whatever code requires for your drawing. 
} 

希望它的工作的。

+0

你能讓我知道如何用CGContext Class來完成? – Developer 2013-05-06 06:08:42

+0

http://lists.apple.com/archives/quartz-dev/2008/Aug/msg00079.html經歷了這一點,與UIBezierPath相同,如果觸摸位於繪圖內部,我們可以設置標誌。因此,您可以使用pathContainsPoint:forMode:而不是containsPoint:設置標誌。 – MadhuP 2013-05-06 06:48:36

0

由於CRDAve提到此鏈接幫助了我很多。請訪問https://github.com/Chintan-Dave/UIImageScanlineFloodfill

和使用下面的代碼中的 - (空)的touchesBegan:(NSSet中*)觸及withEvent:方法(*的UIEvent)事件

if (Fill_clicked==1) { 

    UIImage *image1 = [paintingView.image floodFillFromPoint:lastPoint withColor:newcolor andTolerance:tolorance]; 
    paintingView.image=image1; 
} 

lastpoint是從上面method.I設置tolorance分至10