【问题标题】:CGImageAlphaInfo.Last in iOS 8 unsupported parameter combinationiOS 8 中不支持的参数组合中的 CGImageAlphaInfo.Last
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • 请注意,"iOS 仅支持预乘 alpha。" != "Quartz 仅支持图像的预乘 alpha。"
  • 所以我可以插入 CGImageAlphaInfo alphaInfo = CGImageAlphaInfo.PremultipliedLast 即使打印出 image.AlphaInfo 并看到我的图像的 alpha 信息是 CGImageAlphaInfo.Last?我认为您必须将 alpha 信息与您正在阅读的图像进行匹配,就像您为 Width、Height、BytesPerRow 和 BitsPerComponent 所做的那样?
  • 试试看会发生什么。
猜你喜欢
  • 1970-01-01
  • 2015-11-09
  • 2017-04-06
  • 2017-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-07
相关资源
最近更新 更多