equal
deleted
inserted
replaced
23 |
23 |
24 |
24 |
25 @implementation UIImage (extra) |
25 @implementation UIImage (extra) |
26 |
26 |
27 CGFloat getScreenScale(void) { |
27 CGFloat getScreenScale(void) { |
|
28 float scale = 1.0f; |
28 if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) |
29 if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) |
29 return [UIScreen mainScreen].scale; |
30 scale = [[UIScreen mainScreen] scale]; |
30 else |
31 return scale; |
31 return 1.0f; |
|
32 } |
32 } |
33 |
33 |
34 -(UIImage *)scaleToSize:(CGSize) size { |
34 -(UIImage *)scaleToSize:(CGSize) size { |
35 DLog(@"warning - this is a very expensive operation, you should avoid using it"); |
35 DLog(@"warning - this is a very expensive operation, you should avoid using it"); |
36 |
36 |
37 // Create a bitmap graphics context; this will also set it as the current context |
37 // Create a bitmap graphics context; this will also set it as the current context |
38 if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) |
38 if (UIGraphicsBeginImageContextWithOptions != NULL) |
39 UIGraphicsBeginImageContextWithOptions(size, NO, getScreenScale()); |
39 UIGraphicsBeginImageContextWithOptions(size, NO, getScreenScale()); |
40 else |
40 else |
41 UIGraphicsBeginImageContext(size); |
41 UIGraphicsBeginImageContext(size); |
42 |
42 |
43 // Draw the scaled image in the current context |
43 // Draw the scaled image in the current context |