Bug 7441 - CGBitmapContext constructor always fails with Invalid Handle
Summary: CGBitmapContext constructor always fails with Invalid Handle
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-25 07:26 UTC by Gusman
Modified: 2012-09-26 12:16 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED FEATURE

Description Gusman 2012-09-25 07:26:14 UTC
I have updated to monotouch 6 and now CGBitmapContext constructor always fails with Invalid Handle exception.

Very easy to reproduce:

RectangleF bounds = new RectangleF(0,0,10,10);

byte[] data = new byte[(int)(bounds.Width * bounds.Height * 4)];
CGColorSpace space = CGColorSpace.CreateDeviceRGB();

CGBitmapContext c = new CGBitmapContext(data, (int)bounds.Width, (int)bounds.Height, 8, (int)bounds.Width * 4, space,CGBitmapFlags.None); // <- Exception
Comment 1 Sebastien Pouliot 2012-09-25 08:52:30 UTC
I can duplicate the issue. 

Was the code working on earlier MT releases ? if so do you recall which version you were using before MT 6.0.
Comment 2 Sebastien Pouliot 2012-09-25 09:09:14 UTC
I get the same problem with iOS 5.1. OTOH it works if you use CGImageAlphaInfo instead of CGBitmapFlags

e.g. CGImageAlphaInfo.PremultipliedLast instead of CGBitmapFlags.None
Comment 3 Sebastien Pouliot 2012-09-25 09:14:08 UTC
for that matter CGBitmapFlags.PremultipliedLast works too
while CGBitmapFlags.None == CGBitmapFlags.ByteOrderDefault == 0 fails
Comment 4 Sebastien Pouliot 2012-09-25 09:34:18 UTC
I never noticed this before but it seems to be a (little) known fact [1].

Apple docs [2] says that None and SkipLast should be equivalent - but that's not what happens in real life. I submitted this "bad" documentation to Apple.

Based on this I do not think the None flag worked with earlier MT releases, so I'm closing the issue.


[1] http://stackoverflow.com/q/9408292/220643
[2] https://developer.apple.com/library/ios/#documentation/graphicsimaging/reference/CGImage/Reference/reference.html#//apple_ref/doc/c_ref/CGBitmapInfo
Comment 5 Gusman 2012-09-25 12:41:52 UTC
Ok, thanks.

I didn't used this function since a long time and don't remember if used CGBitmapFlags.PremultipliedLast or CGBitmapFlags.None, so maybe it never worked.
Comment 6 Gusman 2012-09-25 13:10:51 UTC
Hmmm, it seems weird but a lot of values in both enums cause the same exception, as an example, if CGImageAlphaInfo.First (which corresponds to ARGB with no premultiplied alpha) is used it causes the exception.

This can be serious if those formats needed to be used.
Comment 7 Sebastien Pouliot 2012-09-25 17:00:30 UTC
Not every flags are supported on iOS [1] and even then if something is missing you'll need to tell Apple about it (MonoTouch just relay the refusal to create the context as an exception).

[1] https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html#//apple_ref/doc/uid/TP30001066-CH203-CJBEAGHH
Comment 8 Gusman 2012-09-26 12:16:15 UTC
Ok, my bad, sorry for that :)