
代码
extension UIImage { func thumbnails(with options: SomeDrawingOptions) -> UIImage? { // ... UIGraphicsBeginImageContextWithOptions(targetRect.size, false, 0) defer { UIGraphicsEndImageContext() } let cOntext= UIGraphicsGetCurrentContext()! UIColor.white.setFill() context.fill(targetRect) UIBezierPath(roundedRect: targetRect, cornerRadius: 8).addClip() // Drawing image draw(in: targetRect) // Drawing a transparent mask UIColor.black.withAlphaComponent(0.4).setFill() context.fill(targetRect) // Drawing bar UIColor.white.setFill() context.fill(someBarRect) return UIGraphicsGetImageFromCurrentImageContext() } } 参见图片
1 imhui 2016-12-08 22:57:49 +08:00 看起来像是出现了锯齿问题。 试一下改成这样: UIGraphicsBeginImageContextWithOptions(targetRect.size, false, [UIScreen mainScreen].scale) |