우리는 GPUImage와 CIFIlter의 조합을 사용하여 몇 가지 사용자 지정 필터를 만듭니다. 우리가 필터링하는 이미지는 약 2048 X 2048 픽셀입니다. 다음 코드는 약 300MB의 앱 메모리를 차지합니다. 원하는 효과를 얻기 위해 필터를 연결해야하지만 이미지의 메모리 발자국은 결코 공개되지 않습니다. 누군가 조언 할 수 있습니까?메모리 충돌을 일으키는 연결 필터링
UIImage *filteredImage = [self getFilteredImage:initialImage Min:11 Gamma:1.09 Max:226 MinOut:46 MaxOut:208];
filteredImage = [self getFilteredImage:filteredImage Min:34 Gamma:.91 Max:188 MinOut:12 MaxOut:220 forColor:@"red"];
filteredImage = [self getFilteredImage:filteredImage Min:18 Gamma:.89 Max:209 MinOut:32 MaxOut:215 forColor:@"green"];
filteredImage = [self getFilteredImage:filteredImage Min:9 Gamma:1.1 Max:216 MinOut:1 MaxOut:245 forColor:@"blue"];
//Levels
filteredImage = [self getFilteredImage:filteredImage Min:54 Gamma:1.28 Max:232 MinOut:44 MaxOut:179];
filteredImage = [self getFilteredImage:filteredImage Min:15 Gamma:.92 Max:221 MinOut:39 MaxOut:211 forColor:@"red"];
filteredImage = [self getFilteredImage:filteredImage Min:0 Gamma:.9 Max:244 MinOut:15 MaxOut:255 forColor:@"green"];
filteredImage = [self getFilteredImage:filteredImage Min:0 Gamma:1 Max:248 MinOut:16 MaxOut:237 forColor:@"blue"];
+(UIImage*)getFilteredImage: (UIImage*)image Min:(float)min Gamma:(float)gamma Max:(float)max MinOut:(float)minOut MaxOut:(float)maxOut forColor: (NSString*) color
{
GPUImagePicture *gpuImage = [[GPUImagePicture alloc] initWithImage:image];
GPUImageLevelsFilter *levelsFilter = [[GPUImageLevelsFilter alloc] init];
if ([color isEqualToString: @"red"])
{
[levelsFilter setRedMin:[self convertFloat:min] gamma:gamma max:[self convertFloat:max] minOut:[self convertFloat:minOut] maxOut:[self convertFloat:maxOut]];
}else if([color isEqualToString: @"green"])
{
[levelsFilter setGreenMin:[self convertFloat:min] gamma:gamma max:[self convertFloat:max] minOut:[self convertFloat:minOut] maxOut:[self convertFloat:maxOut]];
}
else if([color isEqualToString: @"blue"])
{
[levelsFilter setBlueMin:[self convertFloat:min] gamma:gamma max:[self convertFloat:max] minOut:[self convertFloat:minOut] maxOut:[self convertFloat:maxOut]];
}
else
{
[levelsFilter setMin:[self convertFloat:min] gamma:gamma max:[self convertFloat:max] minOut:[self convertFloat:minOut] maxOut:[self convertFloat:maxOut]];
}
[gpuImage addTarget:levelsFilter];
[gpuImage processImage];
return [levelsFilter imageFromCurrentlyProcessedOutputWithOrientation:image.imageOrientation];
}