我有一个UI
Image,其中一部分被用户选择以清除(使透明).为了做出选择,我用了NSBezierPath.
如何在iOS中清除/使透明的UIImage部分?
解决方法
首先,我假设你有一个UIBezierPath(iOS),而不是一个NSBezierPath(Mac OS X).
为此,您将需要使用核心图形,创建图像上下文,将UIImage绘制到该上下文中,然后清除NSBezierPath指定的区域.
// Create an image context containing the original UIImage. UIGraphicsBeginImageContext(originalImage.size); [originalImage 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,originalImage.size.width,originalImage.size.height); // Build a new UIImage from the image context. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。