TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Day 67 help needed with colorPosterize()

Forums > 100 Days of SwiftUI

I was trying to modify the slidervalue used in the applyProcessing() function when the filter is colorPosterize.

The issue I am finding is there does not seem to be a matching kCIInput key that matches levels the docs say it needs an NSNumber and the name is Levels. Similar to how Sepia uses Intensity

So I thought there would be a kCIInputLevelsKey but that doesnt work...

Can anyone help?

   //code below works
   if inputKeys.contains(kCIInputScaleKey) && (currentFilter.name == "CIPixellate") {
      print("this is pixellate")
      currentFilter.setValue(scaleIntensity * 75, forKey: kCIInputScaleKey) }

    //code below doesnt run as I do not think the Contains is finding the correct kCI key

    if inputKeys.contains(kCIInputIntensityKey) && (currentFilter.name == "CIColorPosterize") {
        print("this is the posterize effect")
      currentFilter.setValue(filterIntensity * 10, forKey: kCIInputIntensityKey) }

3      

Instead of using a constant, try using the string "inputLevels".

3      

That worked perfect! I actually tried a string but I think I put in Levels instead of inputLevels... Here is my code which works awesome!

Thank you so much @roosterboy !!

 func applyProcessing() {
    print(currentFilter.name)
    let inputKeys = currentFilter.inputKeys
    print(inputKeys)

    if inputKeys.contains(kCIInputIntensityKey) {
      currentFilter.setValue(filterIntensity, forKey: kCIInputIntensityKey) }
    if inputKeys.contains(kCIInputRadiusKey) {
      currentFilter.setValue(filterIntensity * 200, forKey: kCIInputRadiusKey) }
    if inputKeys.contains(kCIInputScaleKey) {
      currentFilter.setValue(scaleIntensity * 10, forKey: kCIInputScaleKey) }
    if inputKeys.contains(kCIInputScaleKey) && (currentFilter.name == "CIPixellate") {
      print("this is pixellate")
      currentFilter.setValue(scaleIntensity * 75, forKey: kCIInputScaleKey) }
    if inputKeys.contains("inputLevels") && (currentFilter.name == "CIColorPosterize") {
        print("this is the posterize effect")
      currentFilter.setValue(filterIntensity * 30, forKey: "inputLevels")
    }

    guard let outputImage = currentFilter.outputImage else { return }

    if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) {
      let uiImage = UIImage(cgImage: cgimg)
      image = Image(uiImage: uiImage)
      processedImage = uiImage
    }
  }

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.