0

パスを作成し、すぐに取得して変更しようとしています。問題は、パスが正しく作成および表示されるのに、パスを取得してさらに変更することができないことです。

更新:問題は、2番目の関数でCGContextClosePathを呼び出すと、コンパイラーがこのエラーを返すことです。 :CGContextClosePath:現在のポイントがありません。 基本的に古いパスを「認識」しないため、閉じることはできません。アドバイスをいただければ幸いです。ありがとう!

これが私のコードです:

//Defined at the very beginning outside the functions
CGMutablePathRef _path;

//First function
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];

UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();

[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), BrushSize);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 1.0, 1.0);  
_path = CGPathCreateMutable();

CGContextAddPath (context, _path);

CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);

CGContextStrokePath(context);

drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


//Second function
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();

[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), BrushSize); //1.0); // Brush size

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextSetRGBFillColor(context, 1.0, 0.4, 1.0, 1.0);

CGPathRef pathFill = CGPathCreateCopy (_path);
CGContextAddPath (context, pathFill);

CGContextClosePath(context);
CGContextFillPath(context);

drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
4

1 に答える 1

0

パスをストロークする前に、もう一度パスをコンテキストに追加してみてください。

CGContextAddPath (UIGraphicsGetCurrentContext(), _path);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

うまくいかない場合は、元のパスを使用する代わりに、元のパスのコピーを作成して新しい行を追加してみてください。使用する:

CGPathCreateCopy
于 2012-08-11T14:40:25.963 に答える