Bug 25600 - CGBitmapContext does not accept null colorSpace when using CGImageAlphaInfo.Only
Summary: CGBitmapContext does not accept null colorSpace when using CGImageAlphaInfo.Only
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.6.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-12-23 18:31 UTC by Sarah Ann Tolsma
Modified: 2015-04-16 16:49 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Sarah Ann Tolsma 2014-12-23 18:31:45 UTC
I am attempting to create a new bitmap context, using the following code:

var context = new CGBitmapContext(null, (int)size.Width, (int)size.Height, 8, 0, null, CGImageAlphaInfo.Only);

Note the null handle, and null color space. This should be valid, as noted in Apple's documentation of the available flags at https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html#//apple_ref/doc/uid/TP30001066-CH203

As noted there, when the color space is null, a BPC of 8 with the CGImageAlphaInfo.Only flag is valid. However, I get the following exception when attempting to run this:

Argument cannot be null.
Parameter name: colorSpace

  at MonoTouch.CoreGraphics.CGBitmapContext.GetHandle (MonoTouch.CoreGraphics.CGColorSpace colorSpace) [0x00006] in /Developer/MonoTouch/Source/maccore/src/CoreGraphics/CGBitmapContext.cs:54 
  at MonoTouch.CoreGraphics.CGBitmapContext..ctor (System.Byte[] data, Int32 width, Int32 height, Int32 bitsPerComponent, Int32 bytesPerRow, MonoTouch.CoreGraphics.CGColorSpace colorSpace, CGImageAlphaInfo bitmapInfo) [0x00000] in /Developer/MonoTouch/Source/maccore/src/CoreGraphics/CGBitmapContext.cs:73 
 --- snip ---
Comment 1 Sebastien Pouliot 2014-12-24 12:18:51 UTC
Try using

>    CGColorSpace.Null

instead of `null`. That should give you the behaviour you're looking for.
Comment 2 Sebastien Pouliot 2015-04-16 16:49:38 UTC
While `CGColorSpace.Null` still exists for API compatibility you'll now be able to pass `null` for a CGColorSpace (in XI 8.12+).

Fixed in maccore/master be4919bf6e30d6ab97bea160efa30cb7915167ba

QA: unit tests added in the same revision