开发者

Testing when an UIImage background color has changed

I have a student working on a project where he has a UIImage where he is able to draw a line on the screen. We want to know if you have any idea if he goes back and forth filling the entire screen with lines is there a way to test that every pixel has been covered with the line color? For example if the background is grey and the pen color is blue if he goes back and forth enough the screen will begin to turn blue. We want to test what areas are blue and what areas are still grey.


The following segment of code will draw a line on the screen. If I run a loop the whole screen will eventually be filled with lines,criss crossed back and forth, and the screen will have the color of the line pen color.

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 = UIGraphics开发者_如何学编程GetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


See my answer to this question:

How i count red color pixel from the UIImage using objective-C in iphone?

It contains a link to a demo project that counts the number of red pixels in a UIImage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜