Iphone - Scaling Images Very Slow - Help

I myself scale the images using the following codes. The code is fine and the images are scaled without problems.

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 anyone point out how to improve it?

thank

+3
source share
1 answer

You can try:

CGContextSetInterpolationQuality(context, kCGInterpolationNone);

or

CGContextSetInterpolationQuality(context, kCGInterpolationLow);

and see if any of them cause performance differences with an acceptable level of quality.

+2
source

Source: https://habr.com/ru/post/1767587/


All Articles