cocoaTouch/otherSrc/UIImageScale.m
author koda
Sat, 10 Apr 2010 01:09:29 +0000
changeset 3330 987ec27b6042
parent 3325 652a8ebdf667
permissions -rw-r--r--
add support for modifying the name of the team nicer presentation of hog+hat
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     1
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     2
//  UIImageScale.m
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     3
//  HedgewarsMobile
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     4
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/04/10.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     7
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     8
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     9
#import "UIImageScale.h"
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    10
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    11
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    12
@implementation UIImage (scale)
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    13
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    14
-(UIImage*)scaleToSize:(CGSize)size
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    15
{
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    16
  // Create a bitmap graphics context
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    17
  // This will also set it as the current context
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    18
  UIGraphicsBeginImageContext(size);
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    19
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    20
  // Draw the scaled image in the current context
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    21
  [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    22
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    23
  // Create a new image from current context
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    24
  UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    25
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    26
  // Pop the current context from the stack
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    27
  UIGraphicsEndImageContext();
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    28
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    29
  // Return our new scaled image
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    30
  return scaledImage;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    31
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    32
 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    33
@end