我有一个从 CIImage 加载的 UIImage:
tempImage = [UIImage imageWithCIImage:ciImage];
问题是我需要裁剪tempImage
到一个特定CGRect
的,我知道如何做到这一点的唯一方法是使用CGImage
. 问题是在 iOS 6.0 文档中我发现了这个:
CG图像
If the UIImage object was initialized using a CIImage object, the value of the property is NULL.
A. 如何从 CIImage 转换为 CGImage?我正在使用这段代码,但我有内存泄漏(并且无法理解在哪里):
+(UIImage*)UIImageFromCIImage:(CIImage*)ciImage {
CGSize size = ciImage.extent.size;
UIGraphicsBeginImageContext(size);
CGRect rect;
rect.origin = CGPointZero;
rect.size = size;
UIImage *remImage = [UIImage imageWithCIImage:ciImage];
[remImage drawInRect:rect];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
remImage = nil;
ciImage = nil;
//
return result;
}