1 Reply
      Latest reply on Jun 28, 2019 3:42 PM by gchiste
      devgit Level 1 Level 1 (0 points)

        Hi everyone

        Just getting strated with Swift and iOS.


        I'm looking to create a dithered version of an image in iOS.

        I've captured the image to a UIImageView and have converted to greyscale, with export options to photos.


        imagepicked.image =  convertToGrayScale(image: image) //make greyscale, working.


        imagepicked.image = simpleDitherExample(inputImage: image) //where do I start?

        To create a dithered image like this:



        I understand that the CIDither isn't available until iOS 13, any options now? Any free iOS libraries I can import and call?


        Any help appreciated.



        XCode 10.2.1

        iPhone 7

        • Re: UIImage Dithering
          gchiste Apple Staff Apple Staff (230 points)



          The CIDither filter is actually available as of iOS 12.  To use this filter pre iOS 13 (without the convenience of the CIDither protocol), you can do something like the following:


          let filterParameters: [String: Any] = [
                      "inputImage": inputImage, // a CIImage
                      "inputIntensity": 2.0  // numbers in the range of 0.0 to 5.0 are valid
          let ditherFilter = CIFilter(name: "CIDither", parameters: filterParameters)