我无法重现该问题。我建议记录所有传入参数并将日志附加到您的问题中。还要查看控制台日志,CGBitmapContextCreate 可能会在那里写一些东西,可能会提供有关问题的见解。
更新:
您面临的问题与图像大小无关,而是与位图信息/色彩空间和每个组件的位数的组合有关。这是我在系统日志中尝试使用您提供的信息创建位图上下文的内容:
CGBitmapContextCreate: unsupported parameter combination:
16 bits/component; integer;
64 bits/pixel;
RGB color space model; kCGImageAlphaLast;
kCGImageByteOrder16Little byte order;
4992 bytes/row.
Valid parameters for RGB color space model are:
16 bits per pixel, 5 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipLast
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.
您可以尝试始终或在失败的情况下使用标准的东西,例如
CGContextRef bitmap = CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
8,
0,
CGColorSpaceCreateDeviceRGB(),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
或者让系统为您选择合适的上下文:
UIGraphicsBeginImageContextWithOptions(newRect.size, false, 1.0);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Do your drawing here
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();