Create a circle or a disk with antialiasing for retina display

懵懂的女人 提交于 2019-12-02 02:11:24

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!