Reputation: 29886
How does one scale down a UIImage equally on both dimensions by half?
I have a UIImage that is double the size of the UIImageView and would like it to be the same size, without using any of the content modes for filling or scaling etc.
Upvotes: 1
Views: 3107
Reputation: 1349
Just make yourself a new image (expressed as a category method of UIImage) :
- (UIImage*)scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
Upvotes: 6