0
我有一個學生在一個項目中工作,他有一個UIImage,他可以在屏幕上繪製一條線。我們想知道,如果您有任何想法是否來回填充整個屏幕,是否有一種方法可以測試每個像素是否被線條覆蓋?例如,如果背景是灰色的,並且筆的顏色是藍色的,如果他足夠來回,屏幕將開始變爲藍色。我們想測試哪些區域是藍色的,哪些區域仍然是灰色的。當UIImage背景顏色發生變化時測試
以下代碼段將在屏幕上繪製一條線。如果我運行一個循環,整個屏幕最終將被線條填滿,縱橫交錯,並且屏幕將具有線條顏色的顏色。
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); // sets width of pen
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 1.0, 1.0); // controls color
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();