Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Merely using <code>imageWithCGImage</code> is not sufficient. It will scale, but the result will be blurry and suboptimal whether scaling up or down.</p> <p>If you want to get the aliasing right and get rid of the "jaggies" you need something like this: <a href="http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/" rel="noreferrer">http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/</a>.</p> <p>My working test code looks something like this, which is Trevor's solution with one small adjustment to work with my transparent PNGs:</p> <pre><code>- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize { CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); CGImageRef imageRef = image.CGImage; UIGraphicsBeginImageContextWithOptions(newSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); // Set the quality level to use when rescaling CGContextSetInterpolationQuality(context, kCGInterpolationHigh); CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height); CGContextConcatCTM(context, flipVertical); // Draw into the context; this scales the image CGContextDrawImage(context, newRect, imageRef); // Get the resized image from the context and a UIImage CGImageRef newImageRef = CGBitmapContextCreateImage(context); UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; CGImageRelease(newImageRef); UIGraphicsEndImageContext(); return newImage; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload