Objective-C: resizing an UIImage

-(UIImage*)imageWithImage:(UIImage*)image 
                 scaledToSize:(CGSize)newSize;
{
 UIGraphicsBeginImageContext( newSize );
 [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
 UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 return newImage;
}

 

// grab the original image
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
// scaling set to 2.0 makes the image 1/2 the size. 
UIImage *scaledImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:2.0 orientation:UIImageOrientationUp];