I'm looking for a way to optimize my images by converting its color from 32bit to 16bit rather than just solely resize it. So this is what I'm doing:
- (UIImage *)optimizeImage:(UIImage *)image
{
float newWidth = image.size.width;
float newHeight = image.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, newWidth, newHeight, 5, newWidth * 4,
colorSpace, kCGImageAlphaNone | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGInterpolationQuality quality = kCGInterpolationHigh;
CGContextSetInterpolationQuality(context, quality);
CGImageRef srcImage = CGImageRetain(image.CGImage);
CGContextDrawImage(context, CGRectMake(0, 0, newWidth, newHeight),
srcImage);
CGImageRelease(srcImage);
CGImageRef dst = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage *result = [UIImage imageWithCGImage:dst];
CGImageRelease(dst);
UIGraphicsEndImageContext();
return result;
}
The issue with this piece of code is that when I run it, I get this very error:
CGBitmapContextCreate: unsupported parameter combination: 5 integer
bits/component; 16 bits/pixel; 3-component color space;
kCGImageAlphaNone; 10392 bytes/row.
So my question is: what is the supported combination for CGBitmapContextCreate
? What should I select for the bitmapInfo
parameter in this situation? Please suggest.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…