3
我自己縮放圖像使用下面的代碼。代碼很好,圖像縮放沒有問題。iphone - 縮放圖像速度很慢 - 幫助
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);
唯一的問題是這個代碼的縮放過程非常緩慢。有人可以指出如何改進它?
感謝