Question

I'm using the UIGraphicsGetImageFromCurrentImageContext() function to capture the screen contents into an UIImage object (previously rendered into an Image context). This works great for both the simulator and a real device, however in the latter the resulting image has a few pixels with distorted colors, as seen here:

http://img300.imageshack.us/img300/2788/screencap.png

Please notice the few fucsia pixels at the top navigation bar, at both sides of the search field and to the right of the button. There are also such pixels at the right of the bottom-left button.

The code I'm using to capture the screen view into an UIImage object is pretty straightforward:

UIGraphicsBeginImageContext(self.view.window.frame.size);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

One thing to note is that all the graphics that get distorted belong to custom PNG files, used to draw the search field background as well as the buttons background.

Does anyone knows what could be possible causing this strange color distortion?

Best regards,

Was it helpful?

Solution 2

Solved it by using the just-approved private function UIGetScreenImage().

For more info, please check http://www.tuaw.com/2009/12/15/apple-relents-and-is-now-allowing-uigetscreenimage-for-app-st/ and https://devforums.apple.com/message/149553

Regards,

OTHER TIPS

Just checked my own code that is doing the same thing you are. Yours is nearly identical to mine, except that I am asking the view's layer to render instead of the window's, i.e.:

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

I don't know why that would make a difference, but it's worth a try.

This article explains the issue with image corruption (caused by partially transparent pixels) and provides a workaround which corroborates Chris's comment:

http://www.kaoma.net/iphone/?p=9

UIGetScreenImage() is quite annoying when you just want to capture a view. I found a nice trick, just re-save all your PNG images into TIFF format using Preview.app :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top