iphone - 缩放图像非常慢 - 帮助 [英] iphone - Scaling Images are very slow - Help

查看:118
本文介绍了iphone - 缩放图像非常慢 - 帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码自行缩放图像。代码很好,图像缩放没有问题。

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?

谢谢

推荐答案

您可以尝试:

CGContextSetInterpolationQuality(context, kCGInterpolationNone);

CGContextSetInterpolationQuality(context, kCGInterpolationLow);

并查看其中任何一个是否产生任何性能差异且质量水平可接受。

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

这篇关于iphone - 缩放图像非常慢 - 帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆