I think you can do this using the ImageIO environment, for example:
#import <UIKit/UIKit.h> #import <ImageIO/ImageIO.h> #import <MobileCoreServices/MobileCoreServices.h> #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { UIImage *sourceImage = [UIImage imageNamed:@"test.jpg"]; CFURLRef url = CFURLCreateWithString(NULL, CFSTR("file:///tmp/progressive.jpg"), NULL); CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL); CFRelease(url); NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)kCFBooleanTrue, kCGImagePropertyJFIFIsProgressive, nil]; NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat:.6], kCGImageDestinationLossyCompressionQuality, jfifProperties, kCGImagePropertyJFIFDictionary, nil]; CGImageDestinationAddImage(destination, sourceImage.CGImage, (__bridge CFDictionaryRef)properties); CGImageDestinationFinalize(destination); CFRelease(destination); return 0; } }
Preview.app says the output file is progressive, and the ImageMagick identify
team says it has "interlaced: JPEG."
source share