UIGraphicsBeginImageContext must be Retina-aware?

2019-06-14 23:48发布

问题:

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)