iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
ahmiao
V2EX  ›  iDev

[求助] 在绘制圆角图片时碰到个问题,某些颜色下会出现圆角不光滑的情形

  •  
  •   ahmiao · Dec 8, 2016 · 4131 views
    This topic created in 3579 days ago, the information mentioned may be changed or developed.

    代码

        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()
          }
        }
    

    参见图片

    截图

    2 replies  •  2016-12-09 08:04:09 +08:00
    imhui
        1
    imhui  
       Dec 8, 2016
    看起来像是出现了锯齿问题。
    试一下改成这样:
    UIGraphicsBeginImageContextWithOptions(targetRect.size, false, [UIScreen mainScreen].scale)
    ahmiao
        2
    ahmiao  
    OP
       Dec 9, 2016
    @imhui 嗯,是锯齿,一直没想起这个词。不过传入 [UIScreen mainScreen].scale 和 传入 0 效果是一样的,文档里写了

    > scale The scale factor to apply to the bitmap. If you specify a value of 0.0, the scale factor is set to the scale factor of the device ’ s main screen.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2787 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 14:01 · PVG 22:01 · LAX 07:01 · JFK 10:01
    ♥ Do have faith in what you're doing.