我正在使用自动增强功能来改善很多图像。
但是似乎有很大的泄漏,所以这是我正在使用的代码:
#import <CoreImage/CoreImage.h>
#import <ImageIO/ImageIO.h>
@implementation UIImage (AutoEnhanced)
- (UIImage *)autoEnhancedImage
{
@autoreleasepool {
CIImage *ciOriginal = self.CIImage;
if(!ciOriginal) {
ciOriginal = [[CIImage alloc] initWithCGImage:self.CGImage];
}
NSDictionary *options = @{ CIDetectorImageOrientation : @(self.CGImagePropertyOrientation)};
NSArray *adjustments = [ciOriginal autoAdjustmentFiltersWithOptions:options];
for (CIFilter *filter in adjustments) {
[filter setValue:ciOriginal forKey:kCIInputImageKey];
ciOriginal = filter.outputImage;
}
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:ciOriginal fromRect:ciOriginal.extent];
UIImage *enhancedImage = [[UIImage alloc] initWithCGImage:cgImage];
CGImageRelease(cgImage);
return enhancedImage;
}
}
- (CGImagePropertyOrientation)CGImagePropertyOrientation
{
switch (self.imageOrientation) {
case UIImageOrientationUp:
return kCGImagePropertyOrientationUp;
case UIImageOrientationUpMirrored:
return kCGImagePropertyOrientationUpMirrored;
case UIImageOrientationDown:
return kCGImagePropertyOrientationDown;
case UIImageOrientationDownMirrored:
return kCGImagePropertyOrientationDownMirrored;
case UIImageOrientationLeftMirrored:
return kCGImagePropertyOrientationLeftMirrored;
case UIImageOrientationRight:
return kCGImagePropertyOrientationRight;
case UIImageOrientationRightMirrored:
return kCGImagePropertyOrientationRightMirrored;
case UIImageOrientationLeft:
return kCGImagePropertyOrientationLeft;
}
}
@end
这是Instruments的日志:
即使使用自动释放池,我也无法修复它。任何想法将不胜感激!谢谢!