我正在使用以下代碼來應用圖像過濾器。在我的應用程序中,我正在過濾亮度,對比度和飽和度。我使用三個單獨的滑塊來更改值。隨着我繼續移動這些值,內存消耗超過1.5 GB並崩潰。有沒有一種方法可以減少無崩潰實現的內存消耗?圖像過濾導致高內存消耗和崩潰
(void)setBrightnessAndContrastOf:(UIImage *)image { // forTarget:(UIImageView *)imgView {
if (!image) {
return;
}
CIImage *inputImage = [[CIImage alloc] initWithImage:image];
CIFilter *exposureAdjustmentFilter = [CIFilter filterWithName:@"CIColorControls"];
[exposureAdjustmentFilter setDefaults];
[exposureAdjustmentFilter setValue:inputImage forKey:@"inputImage"];
[exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:self.contrastValue] forKey:@"inputContrast"]; //default = 1.00
[exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:self.brightnessValue] forKey:@"inputBrightness"]; //default = 0.00
[exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:self.saturationValue] forKey:@"inputSaturation"]; //default = 1.00
CIImage *outputImage = [exposureAdjustmentFilter valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef tempImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImage = [UIImage imageWithCGImage:tempImage];
[imageView performSelectorOnMainThread:@selector(setImage:) withObject:newImage waitUntilDone:NO];
CGImageRelease(tempImage);
inputImage = nil;
context = nil;
outputImage = nil;
exposureAdjustmentFilter = nil;
}
在CGImageRelease上設置一個斷點。它被稱爲? – Spectravideo328
@ Spectravideo328我正在使用ARC代碼 – Nassif
編譯器不會自動管理Core Foundation對象的生命週期。因此,您應該釋放它們。 PS:你正在那樣做!現在斷點測試.... – Spectravideo328