UIGraphicsBeginImageContext must be Retina-aware?

拟墨画扇 提交于 2019-12-08 15:49:05

问题


I've read some posts which recommend the use of:

UIGraphicsBeginImageContextWithOptions((image.size), NO, 0.0f) 

instead of:

UIGraphicsBeginImageContext(image.size).

Because the first one uses Retina-scale when drawing, otherwise you get blocky images.

I'm a little confused about when to use or not the retina-scale option.

If i have a photograph which is 1000x1000 px, and i call UIGraphicsBeginImageContext passing those dimensions, am i not specifying exactly how many points i want to draw? Is that ok?

Or should i call UIGraphicsBeginImageContextWithOptions passing half the dimensions (500x500px)? Does it make any difference?


回答1:


You can get the scale value of your device by the following method

[[UIScreen mainScreen] scale]

With this information you can decide how many points you would like to draw.




回答2:


You can create the image context like this:

 UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.mainScreen().scale)


来源:https://stackoverflow.com/questions/11603212/uigraphicsbeginimagecontext-must-be-retina-aware

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