project_files/HedgewarsMobile/Classes/UIImageExtra.m
changeset 4476 4bf74e158f44
parent 4461 2f4f5d649bcd
child 4478 05029b4d8490
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Tue Dec 07 01:18:43 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Wed Dec 08 14:47:52 2010 +0100
@@ -35,7 +35,10 @@
     DLog(@"warning - this is a very expensive operation, you should avoid using it");
 
     // Create a bitmap graphics context; this will also set it as the current context
-    UIGraphicsBeginImageContext(size);
+    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
+        UIGraphicsBeginImageContextWithOptions(size, NO, getScreenScale());
+    else
+        UIGraphicsBeginImageContext(size);
 
     // Draw the scaled image in the current context
     [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
@@ -60,8 +63,9 @@
         DLog(@"Warning, secondImage == nil");
         return self;
     }
-    int w = resultingSize.width;
-    int h = resultingSize.height;
+    CGFloat screenScale = getScreenScale();
+    int w = resultingSize.width * screenScale;
+    int h = resultingSize.height * screenScale;
     
     if (w == 0 || h == 0) {
         DLog(@"Can have 0 dimesions");
@@ -73,14 +77,18 @@
     CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
     
     // draw the two images in the current context
-    CGContextDrawImage(context, CGRectMake(0, 0, self.size.width, self.size.height), [self CGImage]);
-    CGContextDrawImage(context, CGRectMake(secondImagePoint.x, secondImagePoint.y, secondImage.size.width, secondImage.size.height), [secondImage CGImage]);
+    CGContextDrawImage(context, CGRectMake(0, 0, self.size.width*screenScale, self.size.height*screenScale), [self CGImage]);
+    CGContextDrawImage(context, CGRectMake(secondImagePoint.x*screenScale, secondImagePoint.y*screenScale, secondImage.size.width*screenScale, secondImage.size.height*screenScale), [secondImage CGImage]);
     
     // Create bitmap image info from pixel data in current context
     CGImageRef imageRef = CGBitmapContextCreateImage(context);
     
     // Create a new UIImage object
-    UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
+    UIImage *resultImage;
+    if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
+        resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
+    else
+        resultImage = [UIImage imageWithCGImage:imageRef];
 
     // Release colorspace, context and bitmap information
     CGColorSpaceRelease(colorSpace);
@@ -200,9 +208,9 @@
 -(UIImage *)makeRoundCornersOfSize:(CGSize) sizewh {
     CGFloat cornerWidth = sizewh.width;
     CGFloat cornerHeight = sizewh.height;
-    CGFloat theScale = getScreenScale();
-    CGFloat w = self.size.width * theScale;
-    CGFloat h = self.size.height * theScale;
+    CGFloat screenScale = getScreenScale();
+    CGFloat w = self.size.width * screenScale;
+    CGFloat h = self.size.height * screenScale;
 
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
@@ -221,7 +229,7 @@
 
     UIImage *newImage;
     if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
-        newImage = [UIImage imageWithCGImage:imageMasked scale:theScale orientation:UIImageOrientationUp];
+        newImage = [UIImage imageWithCGImage:imageMasked scale:screenScale orientation:UIImageOrientationUp];
     else
         newImage = [UIImage imageWithCGImage:imageMasked];