Я создал приложение для работы с изображениями, но столкнулся с проблемой при добавлении фильтров
Попытка добавить фильтры для нескольких изображений и приложение падает из-за проблемы с памятью.
func apply(_ filter: BanyanFilter, toImage: UIImage, adjustments: [String: Float]) -> UIImage? {
if toImage != image {
inputImage = CIImage(image: toImage)
}
print("Applying Filter: " + filter.name)
filter.adjustments = adjustments
filter.brightness = adjustments["brightness"]!
filter.contrast = adjustments["contrast"]!
filter.exposure = adjustments["exposure"]!
filter.sharpness = adjustments["sharpness"]!
filter.temperature = adjustments["temperature"]!
filter.targetNeutral = adjustments["targetNeutral"]!
filter.inputImage = inputImage
let cgImage = context.createCGImage(filter.outputImage!, from: filter.outputImage!.extent)!
let finalFilterImage = UIImage(cgImage: cgImage, scale: toImage.scale, orientation: toImage.imageOrientation)
let finalImage = applyAdjustments(filter: filter, toImage: finalFilterImage)
if filter.brightness == 0.0 { filter.brightness = filter.brightnessFilterDefault}
if filter.contrast == 1.0 { filter.contrast = filter.contrastFilterDefault}
if filter.exposure == 0.0 { filter.exposure = filter.exposureFilterDefault}
if filter.sharpness == 0.0 { filter.sharpness = filter.sharpnessFilterDefault}
if filter.temperature == 6500.0 { filter.temperature = filter.temperatureFilterDefault}
if filter.targetNeutral == 6500.0 { filter.targetNeutral = filter.targetNeutralFilterDefault}
return finalImage
}