Bug 15199 - Capture screen image is black
Summary: Capture screen image is black
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.0.0.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-10-04 07:42 UTC by Amanda
Modified: 2014-03-26 08:08 UTC (History)
3 users (show)

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

Test Case Project Files (669.11 KB, application/zip)
2013-10-08 08:43 UTC, Amanda

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 Amanda 2013-10-04 07:42:17 UTC

After upgrading to iOS7, the following piece of code now returns a black image:

  using (var screenImage =  CGImage.ScreenImage.WithImageInRect(new RectangleF( UIScreen.MainScreen.Bounds.GetMidX() - 25, 75 , 50, 50)))


Obviously, the camera is open and active as this code happens first:

	ColourPickView myOverlay = new ColourPickView (this);
			var cameraType = UIImagePickerControllerSourceType.Camera; 
			if (UIImagePickerController.IsSourceTypeAvailable (cameraType)) {
				_picker = new UIImagePickerController (); 
				Picker.SourceType = cameraType;
				Picker.ShowsCameraControls = false; 
				Picker.CameraOverlayView = myOverlay.View; 
				Picker.ContentSizeForViewInPopover = new SizeF (100, 150);
				Picker.Canceled += delegate {
					this.DismissViewController(true, delegate {
				Picker.FinishedPickingMedia += delegate {
					this.DismissViewController(true,delegate {
					} ); 
				myOverlay.BubbleClick += new EventHandler (myOverlay_BubbleClick);
				myOverlay.SearchClick += new EventHandler(myOverlay_SearchClick);
				this.PresentViewController (Picker, true, delegate {

Everything seems fine and I can see the view through the camera viewfinder as expected. No changes have been made since iOS6.


Comment 1 Sebastien Pouliot 2013-10-04 08:21:17 UTC
`SceenImage` uses `UIGetScreenImage()` which Apple deprecated and removed from the public API a while ago. I suspect the feature was completely removed in iOS7.

The official Apple alternative [1] way to get a "screenshot" is implemented in `UIScreen.Capture ()`.

[1] https://developer.apple.com/library/ios/#qa/qa2010/qa1703.html
Comment 2 Amanda 2013-10-04 08:32:02 UTC
Thanks very much Sebastian


Comment 3 Sebastien Pouliot 2013-10-07 11:12:23 UTC
Based on last comment I'll assume this fixed the issue. Please re-open if that was not the case.
Comment 4 Sebastien Pouliot 2013-10-07 11:30:18 UTC
Future versions will automatically call UIScreen.Capture when ScreenImage is used.
master 83f263bd09d672c21ff91d999bd9bbbe2299fb60
Comment 5 Amanda 2013-10-08 07:00:06 UTC
Hi Sebastian

Unfortunately i still have my problem as such:

The CGImage.ScreenImage.WithImageInRect( and UISCreen.MainScreen.Capture() both take a snapshot of the views open on the iPhone. However they can no longer capture the color information that is presented by the camera view prior to taking a photo.

Prior to iOS7, I was able to take a partial snapshot (a specific  area) of what the camera was seeing, and then analyse and process the pixel data. Now, the color information is all black. I want to analyze a certain area of what the camera is seeing, and not the entire image that is created when the UIImagePickerController snaps an image.


Comment 6 Sebastien Pouliot 2013-10-08 07:51:39 UTC
Please attach a small self-contained test case that works on iOS6. We'll have a look to see if that's still possible with iOS7.
Comment 7 Amanda 2013-10-08 08:33:32 UTC
Hi Sebastian

I have attached a skinny version of my project. Also, you can download the app SugarSnap from iStore to see it working fully (in iOS6)

Thanks and Regards

Comment 8 Amanda 2013-10-08 08:43:54 UTC
Created attachment 5086 [details]
Test Case Project Files
Comment 9 Sebastien Pouliot 2013-10-08 09:58:57 UTC
Apple [1] recommended (and supported) approach to capture renders every window into the context. However the camera output is not something that can be rendered - so it's not part of the screenshot.

I see you looked at the new API [2] in iOS7, which removes another option. Still you might want to try if the OpenGL approach can work for your app (the capture technique is different and the normal approach returns "black", empty, content). You'll need to use an EAGLView for this (but the same iOS7 code should work on it).

Otherwise you'll have to change your approach to get the video/image from the camera (not the screen).

[1] https://developer.apple.com/library/ios/#qa/qa2010/qa1703.html
[2] http://blog.xamarin.com/snapshotting-views-in-ios-7/
Comment 10 Amanda 2013-10-09 02:51:50 UTC
Hi Sebastian

Thanks for that. I am now trying the AVFoundation approach - more or less getting it to work. 

I am seeing a blue-ish  image at the moment - going to play around with it for a bit.

Best Regards

Comment 11 Amanda 2013-10-14 04:21:58 UTC
Hi Sebastian

Just to let you know.. I have got it working again perfectly using the AVFoundation. 


Comment 12 Mohit Kheterpal 2014-03-26 08:08:18 UTC
As per comment 11, this issue is working fine now.

Hence closing this issue by marking it as verified.