画像(270度の円、pacmanロゴに似ており、Core Graphicsとしてペイントされています)を使用してマスクを作成しようとしています。私がしているのはこれです
1.コアグラフィックスパスの作成
CGContextSaveGState(context);
CGContextBeginPath(context);
CGContextMoveToPoint(context,circleCenter.x,circleCenter.y);
//CGContextSetAllowsAntialiasing(myBitmapContext, YES);
CGContextAddArc(context,circleCenter.x, circleCenter.y,circleRadius,startingAngle, endingAngle, 0); // 0 is counterclockwise
CGContextClosePath(context);
CGContextSetRGBStrokeColor(context,1.0,0.0,0.0,1.0);
CGContextSetRGBFillColor(context,1.0,0.0,0.0,0.2);
CGContextDrawPath(context, kCGPathFillStroke);
2.次に、パスがペイントされたばかりのパスのイメージを作成しています
CGImageRef pacmanImage = CGBitmapContextCreateImage (context);
3.コンテキストを復元する
CGContextRestoreGState(context);
CGContextSaveGState(context);
4. 1ビットマスクを作成します(これにより、白黒マスクが提供されます)
bitsPerComponent = 1;
bitsPerPixel = bitsPerComponent * 1 ;
bytesPerRow = (CGImageGetWidth(imgToMaskRef) * bitsPerPixel);
mask = CGImageCreate(CGImageGetWidth(imgToMaskRef),
CGImageGetHeight(imgToMaskRef),
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
greyColorSpace,
kCGImageAlphaNone,
CGImageGetDataProvider(pacmanImage),
NULL, //decode
YES, //shouldInterpolate
kCGRenderingIntentDefault);
5. imgToMaskRef(CGImageRef imgToMaskRef = imgToMask.CGImage;)を、作成したばかりのマスクでマスクします。
imageMaskedWithImage = CGImageCreateWithMask(imgToMaskRef, mask);
CGContextDrawImage(context,imgRectBox, imageMaskedWithImage);
CGImageRef maskedImageFinal = CGBitmapContextCreateImage (context);
6. maskedImageFinalをこのメソッドの呼び出し元(CGImageRefであるwheelChoiceMadeStateとして)に返し、呼び出し元はCALayerのコンテンツプロパティを画像で更新します
theLayer.contents = (id) wheelChoiceMadeState;
私が見ている問題は、マスクが適切に機能せず、実際に非常に奇妙に見えることです。CoreGraphicsによってペイントされたパス全体に奇妙なパターンが表示されます。私の勘では、CGImageGetDataProvider()に何かがあるのですが、よくわかりません。
どんな助けでもいただければ幸いです
ありがとうございました