2014-09-18 57 views
0

我收到iOS 8的iOS 7異常。異常情況是「無效句柄」,消息: :CGBitmapContextCreate:不受支持的參數組合:8整數位/分量; 32位/像素; 3分量色彩空間; kCGImageAlphaLast; 524字節/行。CGImageAlphaInfo.Last in iOS 8不受支持的參數組合

任何想法爲什麼這不再是一個支持的參數?我已經將它追蹤到下面的代碼中我的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工作室5.4(建立240)

+0

更多的代碼和圖像本身將有助於診斷爲什麼這停止工作。 – poupou 2014-09-19 00:17:41

回答

1

的iOS僅支持預乘alpha。改爲使用CGImageAlphaInfo.PremultipliedLast

Quartz 2D Programming Guide的「支持的位圖格式」部分沒有列出使用kCGImageAlphaInfoLast的任何格式。 據我所知,自iOS 2.0以來這並沒有改變。

+0

請注意*「iOS僅支持預乘alpha。」*!= *「Quartz支持僅預乘alpha圖像。」* – poupou 2014-09-19 00:16:08

+0

您是對的。這是錯誤的參考。 – 2014-09-19 00:32:57

+0

所以我可以插入CGImageAlphaInfo alphaInfo = CGImageAlphaInfo.PremultipliedLast即使如果打印出image.AlphaInfo,並看到我的圖像的alpha信息是CGImageAlphaInfo.Last?我以爲你必須匹配你正在閱讀的圖像的alpha信息,就像你對寬度,高度,BytesPerRow和BitsPerComponent? – LampShade 2014-09-19 14:42:33

相關問題