ios - CGImageAlphaInfo.Last 在 iOS 8 中不受支持的参数组合

标签 ios xamarin.ios core-graphics ios8

我从适用于 iOS 7 的 iOS 8 中得到一个异常。异常是“无效句柄”,并显示消息: :CGBitmapContextCreate:不支持的参数组合:8个整数位/组件; 32 位/像素;三分量色彩空间; kCGImageAlphaLast; 524 字节/行。

知道为什么这不再是受支持的参数吗?我已经将其追踪到我的 PNG 图像在下面的代码中使用的 alpha 信息“CGImageAlphaInfo.Last”,其中我指定了 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(内部版本 240)

最佳答案

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

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

关于ios - CGImageAlphaInfo.Last 在 iOS 8 中不受支持的参数组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25922859/

相关文章:

ios - 人们在代码编译时如何有效地利用时间?

ios - 在使用 xamarin 的应用程序购买中努力测试 IOS

iPad FormSheet/PageSheet 模态视图,旋转时会填满整个屏幕。T

ios - 如何在 iPhone 上用手指触摸画出模糊线?

ios - 当 HotSpot 通过 USB 开启时,可达性报告 Wifi

ios - 有崩溃报告、dsym 文件但没有 ipa/xarchive : How to symbolicate the crash log?

iphone - MonoTouch是iPhone开发的可行平台吗?

iphone - 如何在 iPhone/iPad 上为线条添加纹理

ios - 在drawRect内绘制透明的UIBezierPath线

iOS 7 在单线程安全上没有合并冲突