長方形に丸いオブジェクトを含むjpg画像があり、丸いオブジェクトの環境を透明にしたい...
(この例では赤い領域を削除します)
このiOSの助けを借りて、UIImageの一部を透明にし、「UIBezierPath bezierPathWithOvalInRect」で少し成功しましたが、これでオブジェクトの周りにパスが作成され、オブジェクトの内側ではなく外側を作成するために、オブジェクトを反転する必要があります。パスは透過的です。
正しい結果を得るためにコードをどこで変更しなければならないのかわからない。
これが私のコードです:
//BezierPath
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)];
// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(_imgTemp.image.size);
[_imgTemp.image drawAtPoint:CGPointZero];
// Clip to the bezier path and clear that portion of the image.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context,bezierPath.CGPath);
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height));
// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self._imgTemp.image = newImage;
誰かが解決しましたか?