Retina display core graphics font quality

前端 未结 4 773
醉酒成梦
醉酒成梦 2020-12-15 21:18

Trying to understand why am I getting low quality drawing with CGContextShowTextAtPoint? See attached image: \"img\"

相关标签:
4条回答
  • 2020-12-15 21:47

    Does using CGContextScaleCTM deliver any results for you? When working with a graphics context, something like this:

    CGFloat scale = [[UIScreen mainScreen] scale];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextScaleCTM(context, scale, scale);
    
    0 讨论(0)
  • 2020-12-15 21:56

    By default, your CALayer is not rendering its Quartz content at the higher resolution of the Retina display screen. You can enable this using code like the following:

    if ([layer respondsToSelector:@selector(setContentsScale:)])
    {
        layer.contentsScale = [[UIScreen mainScreen] scale];
    }
    

    This will affect not just text rendering, but all of your Quartz drawing within CALayers, so you'll need to do this for all of your layers with custom Quartz content.

    0 讨论(0)
  • 2020-12-15 22:13

    Swift version:

    textLayer.contentsScale = UIScreen.mainScreen().scale
    

    0 讨论(0)
  • 2020-12-15 22:14

    A group of functions controls how Core Graphics renders fonts:

    • CGContextSetAllowsAntialiasing
    • CGContextSetAllowsFontSmoothing
    • CGContextSetAllowsFontSubpixelPositioning
    • CGContextSetAllowsFontSubpixelQuantization
    0 讨论(0)
提交回复
热议问题