【发布时间】:2014-09-18 21:43:11
【问题描述】:
从 iOS 8 开始,我遇到了一个适用于 iOS 7 的异常。异常是“无效句柄”,并显示以下消息: :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 xamarin.ios core-graphics ios8