我只想获得不规则形状内的那些像素。使用核心图形而不是 openGL。这是我绘制不规则形状的图像。
这是绘图代码
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(drawLineClicked)
{
UITouch *touch = [touches anyObject];
if ([touch view] == EditImageView)
{
lastPoint = [touch locationInView:self.view];
[self drawLines:10.0 andColorWithRed:1.0 Green:0.0 Blue:0.0 Alpha:1.0];
[self.view setNeedsDisplay];
currentPoint = lastPoint;
}
}
}
-(void)drawLines:(CGFloat)withWidth andColorWithRed:(CGFloat)red Green:(CGFloat)green Blue:(CGFloat)blue Alpha:(CGFloat)alpha
{
UIGraphicsBeginImageContext(Image.size);
[EditImageView.image drawInRect:CGRectMake(0, 0, Image.size.width, Image.size.height)];
ctx = UIGraphicsGetCurrentContext();
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetAllowsAntialiasing(ctx,TRUE);
CGContextFlush(ctx);
//sets the line width for a graphic context
CGContextSetLineWidth(ctx,withWidth);
//set the line colour
CGContextSetRGBStrokeColor(ctx, red, green, blue, alpha);
CGContextMoveToPoint(ctx, currentPoint.x, currentPoint.y);
CGContextAddLineToPoint(ctx, lastPoint.x,lastPoint.y);
CGContextStrokePath(ctx);
EditImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}