在我的项目中,我需要将任何格式的图像转换为渐进式JPEG。我该怎么做?
我尝试了这样做,但没有成功。
我尝试了这样做,但没有成功。
let sourceImage = UIImage(named: "example.jpg")
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let url = CFURLCreateWithString(kCFAllocatorDefault,paths.stringByAppendingPathComponent("progressive.jpg") 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!)
CGDataConsumer(url_close):写入失败。
- Eric Ayalet done = CGImageDestinationFinalize(destinationRef!); print(done)
打印出了"true"。但是什么都没有被写入,而且错误信息弹出了。 - Eric Aya