1 Reply
      Latest reply on Apr 17, 2019 9:51 PM by Claude31
      tarekabdallah Level 1 Level 1 (0 points)

        I am trying to convert a png image to interlaced in order to have a better image loading experience. However, whenever i am trying to set kCGImagePropertyPNGInterlaceType i am facing an issue with the type and i could not find anything on the internet. My code is as follows:

                    if let image = selectedImage{
                        let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("progressive.png")
                        let fileUrl = NSURL(fileURLWithPath: path as String, isDirectory: true)
                        let url = CFURLCreateWithString(kCFAllocatorDefault,(fileUrl.absoluteString! as CFString)  , nil)
                        let destinationRef = CGImageDestinationCreateWithURL(url!, kUTTypePNG, 1, nil)
                        let pngProperties = NSDictionary(dictionary: [kCGImagePropertyPNGInterlaceType:])/* can't find the
                        correct value to fill in the dictionary for th key kCGImagePropertyPNGInterlaceType */
                        let properties = NSDictionary(dictionary: [kCGImagePropertyPNGDictionary:pngProperties])
                        CGImageDestinationAddImage(destinationRef!, (image.cgImage)!, properties)
                        let data = try! Data(contentsOf: fileUrl as URL) // to be uploaded to server