1

Anyone know how to update this code for iOS 8? I am getting this error message:

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedFirst; 4294967289 bytes/row.

CGContextRef CreateBitmapContenxtFromSizeWithData(CGSize s, void* data)
{
    int w = s.width, h = s.height;
    int bitsPerComponent = 8;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    int components = 4;
    int bytesPerRow = (w * bitsPerComponent * components + 7)/8;

    CGContextRef result = CGBitmapContextCreate(data, w, h, 8, bytesPerRow, colorSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
    CGColorSpaceRelease(colorSpace);
    return result;
}
GameDroids
  • 5,584
  • 6
  • 40
  • 59
mikomi
  • 5
  • 5

1 Answers1

0

Bytes per row is calculated incorrectly in the above snippet.

To calculate the bytes per row, you can just take the width of your image and multiply it with the count of bits per pixel, which seems to be four in your case.

int bytesPerRow = w * 4;

Be careful though, if data points to image data that is stored in RGB, you have three bytes per pixel. You will also need to pass the CGImageAlphaInfo.NoneSkipFirst flag as last parameter to CGBitmapContextCreate so the alpha channel is omitted.

Emiswelt
  • 3,909
  • 1
  • 38
  • 56