JPEG Compression Quality using CGImage
Final Update
After extensive research and following the suggestions in the comments above it appears that there is no way to disable chroma subsampling/decimation with any of Apple’s built-in APIs short of setting kCGImageDestinationLossyCompressionQuality
to 1.0
which results in very large images.
If you need to be able to control chroma subsampling/decimation yourself when saving to JPEG then you’ll need to use a 3rd party library such as libjpeg.
Maybe there’s some other API I could use?
WebP is a new image format from Google that gives you better compression than jpg and png, both lossless and lossy. There is a project on github that is pretty easy to use: https://github.com/seanooi/iOS-WebP
You just add a category and the WebP framework to your project to use it.
//Converting To WebP// quality value is [0, 100]NSData *webpData = [UIImage imageToWebP:[UIImage imageNamed:@"image.jpg"] quality:75];//Converting From WebPUIImage *webPImage = [UIImage imageFromWebP:@"/path/to/file"];//Setting image transparency//alpha value is [0, 1]UIImage *transparencyImage = [[UIImage imageNamed:image.jpg] imageByApplyingAlpha:0.5];
The alpha isn't working right, but since you are using jpg, I'm assuming you don't need it.