我从适用于 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/