BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.