CGBitmapContextCreate已停止为iOS 9工作

时间:2016-02-11 23:10:58

标签: ios swift swift2 core-graphics

因此,这段代码曾用于iOS 8,但已停止在iOS 9上工作

let bitsPerComponent = CGImageGetBitsPerComponent(cgImage)
let colorSpace = CGImageGetColorSpace(cgImage)
let bitmapInfo = CGImageGetBitmapInfo(cgImage)
let context =
    CGBitmapContextCreate(
        nil, newPixelWidth, newPixelHeight, bitsPerComponent, 0, colorSpace,
        bitmapInfo.rawValue)

CoreGraphics的解释是:

CGBitmapContextCreate: unsupported parameter combination:
    8 integer bits/component;
    32 bits/pixel;
    RGB color space model; kCGImageAlphaLast;
    2400 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
    128 bits per pixel,      32 bits per component,      kCGImageAlphaNoneSkipLast |kCGBitmapFloatComponents
    128 bits per pixel,      32 bits per component,      kCGImageAlphaPremultipliedLast |kCGBitmapFloatComponents

但是newPixelWidth是600和600 * 4 = 2400.这里的交易是什么?

1 个答案:

答案 0 :(得分:3)

我没有专家,但你没有给出自己的答案吗?

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

这些都不是kCGImageAlphaLast,所以我认为这是问题所在。