UIView captured image has distorted colors (iPhone SDK)

I am using the UIGraphicsGetImageFromCurrentImageContext () function to capture the contents of the screen into a UIImage object (previously displayed in the image context). This works great for both the simulator and the real device, however, in the last resulting image there are several pixels with distorted colors, as shown here:

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

Notice the few fucsia pixels on the top navigation bar, on both sides of the search field and to the right of the button. There are also such pixels to the right of the lower left button.

The code I use to capture the screen into a UIImage object is pretty simple:

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

It should be noted that all distorted graphics relate to custom PNG files used to draw the background of the search field, as well as the background of the buttons.

Does anyone know what could be causing this strange color distortion?

Yours faithfully,

+3
source share
4 answers

Solved it using the newly approved private function UIGetScreenImage ().

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

Hello,

+1
source

, , . , , , ..:

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

, , .

+1

This article explains the problem with image corruption (caused by partially transparent pixels) and provides a workaround that confirms Chris's comment:

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

+1
source

UIGetScreenImage () is pretty annoying when you just want to capture a view. I found a good trick, just saved all your PNG images in TIFF format using Preview.app :)

0
source

Source: https://habr.com/ru/post/1725646/


All Articles