Create a circle or a disk with antialiasing for retina display

前端 未结 1 1229
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 20:33

I have creating a circle using CGContextFillEllipseInRect from CoreGraphic.

I\'m using this circle (which is actually a disk) to replace the <

1条回答
  •  借酒劲吻你
    2021-01-21 21:26

    The problem is that you are creating a non-retina graphics context when using UIGraphicsBeginImageContext, as mentioned in the documentation:

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

    Instead you should be using UIGraphicsBeginImageContextWithOptions to create your image context. You can keep passing NO for the opaque parameter if you want an image that supports transparency (same as what you are implicitly doing now).

    In most cases you can pass 0.0 for the scale factor. This sets the scale factor to that of the device's main screen. Again, as mentioned in the documentation:

    If you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen.


    So, in short, you should create your image context like this:

    UIGraphicsBeginImageContextWithOptions(rectForDisk.size, false, 0.0) // false for Swift
    

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