iOS make part of an UIImage transparent

后端 未结 2 1509
情深已故
情深已故 2020-12-30 08:50

I have an UIImage where part of it has been selected by the user to clear out (make transparent). To make the selection I used NSBezierPath.

How can I clear/make tra

2条回答
  •  北海茫月
    2020-12-30 09:18

    Swift4 solution from landweber's above answer:

    UIGraphicsBeginImageContext(image!.size)
    image!.draw(at: CGPoint.zero)
    let context:CGContext = UIGraphicsGetCurrentContext()!;
    let bez = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 10, height: 10))
    context.addPath(bez.cgPath)
    context.clip();
    context.clear(CGRect(x: 0,y: 0,width: image!.size.width,height: image!.size.height));
    let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;
    UIGraphicsEndImageContext();
    

提交回复
热议问题