我们正在使用 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];
}