How come my drawing code keeps resulting in fuzzy shapes?

前端 未结 1 2036
礼貌的吻别
礼貌的吻别 2020-12-11 13:44

No matter what I do, I can\'t seem to figure out why my images keep coming out fuzzy on iOS displays. It doesn\'t matter whether it\'s one I created in an image editor or dr

1条回答
  •  有刺的猬
    2020-12-11 13:54

    UIGraphicsBeginImageContext:

    ... is equivalent to calling the UIGraphicsBeginImageContextWithOptions function with the opaque parameter set to NO and a scale factor of 1.0.

    However, UIGraphicsBeginImageContextWithOptions defines its scale parameter as:

    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.

    So your use of UIGraphicsBeginImageContextWithOptions is creating a context with a scale of 1.0. That's correct for e.g. last year's iPad Mini but all retina-class devices have a 'native' scale of 2.0 — two pixels per logical point. UIGraphicsBeginImageContextWithOptions introduced the special case of 0.0 so that you don't have to mess about dealing with getting the correct number for that device for yourself (though [[UIScreen mainScreen] scale] would be an easy way).

    So switch your exiting call to UIGraphicsBeginImageContext(CGSizeMake(1000, 1000)) to:

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(1000, 1000), NO, 0.0)
    

    Otherwise the context you create will have a quarter as many pixels as the screen does in the corresponding amount of space.

    0 讨论(0)
提交回复
热议问题