Iphone 从应用于现有UIImage的变换生成新UIImage的最快方法是什么?

Iphone 从应用于现有UIImage的变换生成新UIImage的最快方法是什么?,iphone,cocoa-touch,uikit,uiimage,core-graphics,Iphone,Cocoa Touch,Uikit,Uiimage,Core Graphics,我试图拍摄一张从后置摄像头拍摄的图像,对其应用缩放变换,然后输出一张与原始图像大小相同但放大的新图像 我下面的工作。。。但是它很慢,尤其是UIGraphicsBeginImageContextsize之间的代码;和图像背景 有更好的方法吗?特别是,一种能产生相同结果但更快的方法 UIImage *tempImage = [[UIImage alloc] initWithData:imageData]; CGImageRef img = [tempImage CGImage]; CGFloat

我试图拍摄一张从后置摄像头拍摄的图像,对其应用缩放变换,然后输出一张与原始图像大小相同但放大的新图像

我下面的工作。。。但是它很慢,尤其是UIGraphicsBeginImageContextsize之间的代码;和图像背景

有更好的方法吗?特别是,一种能产生相同结果但更快的方法

UIImage *tempImage = [[UIImage alloc] initWithData:imageData];

CGImageRef img = [tempImage CGImage];
CGFloat width = CGImageGetWidth(img);
CGFloat height = CGImageGetHeight(img);
CGRect bounds = CGRectMake(0, 0, width, height);
CGSize size = bounds.size;

CGFloat z = 5.0; 
CGAffineTransform xfrm = CGAffineTransformMakeScale(z, z);

UIGraphicsBeginImageContext(size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextConcatCTM(currentContext, xfrm);
CGContextDrawImage(currentContext, bounds, img);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

谢谢-wg

答案很简单:先裁剪,然后缩放

UIImage的大小可能相当大,尤其是在通过相机拍摄照片质量时,导致放大时性能不佳。因此,最佳做法是首先将照片裁剪到所需大小,然后根据需要进行缩放