views:

45

answers:

1

Hello All

I am scaling images by myself using the following codes. The code is fine and the images are scaled without problem.

UIImage *originImg = img;
size = newSize;
if (originImg.size.width > originImg.size.height) {
    newSize = CGSizeMake(size.width, originImg.size.height * size.width / originImg.size.width);
} else {
    newSize = CGSizeMake(originImg.size.width * size.height / originImg.size.height, size.height);
}

UIGraphicsBeginImageContext(newSize);

CGContextRef context = CGContextRetain(UIGraphicsGetCurrentContext());
CGContextTranslateCTM(context, 0.0, newSize.height);
CGContextScaleCTM(context, 1.0, -1.0);

CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, newSize.width, newSize.height), originImg.CGImage);

UIImage* scaledImage = [UIGraphicsGetImageFromCurrentImageContext() retain];

UIGraphicsEndImageContext();
CGContextRelease(context);

The only problem is that the scaling process from this code is very slow. Can someone point out how to improve it?

thanks

+1  A: 

You could try either:

CGContextSetInterpolationQuality(context, kCGInterpolationNone);

or

CGContextSetInterpolationQuality(context, kCGInterpolationLow);

and see if either of those produce any performance differences with an acceptable quality level.

hotpaw2