iOS 8中的CGImageAlphaInfo.Last不支持的参数组合

时间:2014-09-18 21:43:11

标签: ios xamarin.ios core-graphics ios8

我在iOS 8中获得了一个适用于iOS 7的例外。例外是"无效句柄"随着消息: :CGBitmapContextCreate:不支持的参数组合:8个整数位/组件; 32位/像素; 3组分色彩空间; kCGImageAlphaLast; 524字节/行。

为什么这不再是受支持的参数?我已将其追踪到alpha信息" CGImageAlphaInfo.Last"我在下面的代码中使用了我的PNG图像,我在其中指定了CGImageAlphaInfo alphaInfo = image.AlphaInfo;我在函数中使用的一些其他图像具有" CGImageAlphaInfo.PremultipliedFirst"不会导致异常的alpha信息。所以我现在强迫alpha信息为PremultipliedFirst。

            CGImage image = uiimage.CGImage;
            int width = image.Width;
            int height = image.Height;
            CGColorSpace colorSpace = image.ColorSpace;
            int bytesPerRow = image.BytesPerRow;
            int bitmapByteCount = bytesPerRow * height;
            int bitsPerComponent = image.BitsPerComponent;
            CGImageAlphaInfo alphaInfo = image.AlphaInfo;

            // Allocate memory because the BitmapData is unmanaged
            IntPtr BitmapData = Marshal.AllocHGlobal(bitmapByteCount);

            CGBitmapContext context = new CGBitmapContext(BitmapData, width, height, bitsPerComponent, bytesPerRow, colorSpace, alphaInfo);

我正在使用:

XCode版本6.0.1(6A317)

Xamarin Studio 5.4(build 240)

1 个答案:

答案 0 :(得分:2)

iOS仅支持预乘alpha。请改用CGImageAlphaInfo.PremultipliedLast

Quartz 2D Programming Guide的“支持的位图格式”部分未使用kCGImageAlphaInfoLast列出任何格式。 据我所知,自iOS 2.0以来,这并没有改变。