swift 3.0を使用してUIImageをプログレッシブJPEGに変換する必要があります。私は、SWIFT 2.2で次のコードを発見した :スウィフト3.0で画像をプログレッシブJPEGに変換
let sourceImage = UIImage(named: "example.jpg")
let path = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString).stringByAppendingPathComponent("progressive.jpg")
let fileUrl = NSURL(fileURLWithPath: path as String, isDirectory: true)
let url = CFURLCreateWithString(kCFAllocatorDefault,fileUrl.absoluteString as CFString , nil)
let destinationRef = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, nil)
let jfifProperties = NSDictionary(dictionary: [kCGImagePropertyJFIFIsProgressive:kCFBooleanTrue])
let properties = NSDictionary(dictionary: [kCGImageDestinationLossyCompressionQuality:0.6,kCGImagePropertyJFIFDictionary:jfifProperties])
CGImageDestinationAddImage(destinationRef!, (sourceImage?.CGImage)!, properties)
CGImageDestinationFinalize(destinationRef!)
をしかし、それは、SWIFT 3.0では動作しません。 CGImageDestinationCreateWithURLはエラーを返します(すべてのCGImageクラス...)何か助けてください?ありがとう!
「私は、次のコードを発見しました」。理解していないコードは使用しないでください。 – Sulthan
ありがとうございました。ほんとうにありがとう! –