For a method to physically scale any UIImage, I need to create bitmap context that has exact same settings as the image except for target width and height.
Here is my code so far. What is missing: How can I determine number of components per pixel of a CGImage for the bytesPerRow parameter of CGBitmapContextCreate?
CGImageRef cgImage = self.CGImage;
size_t widthPX = CGImageGetWidth(cgImage);
size_t heightPX = CGImageGetHeight(cgImage);
size_t bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
size_t bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage);
CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(colorSpace);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(cgImage);
CGContextRef ctx = CGBitmapContextCreate(NULL, destWidth, destHeight, bitsPerComponent, bytesPerRow /wrong!! it is for source width!/, colorSpace, bitmapInfo);