"renderInContext:" and CATransform3D

I have a view in which there are mutifixes inside it, and a view of the image (in other words, a "flow stream") ... And I need to take a screenshot programmatically!

Since the docs indicate that "renderInContext:" will not display 3D animations:

"Important. Implementation of this method Mac OS X v10.5 does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer are not displayed. In addition, layers that use 3D transforms are not displayed, and not layers that define backgroundFilters , filters, compositingFilter, or mask values. Future versions of Mac OS X may add support for rendering these layers and properties. "

source: https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html

I searched a lot and my “best” solution (this is not very good) is to create my own CGContext and write all the CG animations to it. But I really don't want to do this, because I will need to rewrite most of my animation codes, and it will be very expensive for memory ... I found other solutions (some of which were not available) like using openGL or capturing via AVSessions, but no one can help me ...

What are my options? Anyone with this problem?

Thank you for your time!

+4
source share
3 answers

I worked with protocols .... I implement a protocol in all UIViews classes that do 3D transforms. So when I request a screenshot, it takes all the subviews screenshots and generates one UIImage. Not so good for a lot of views, but I do a few views.

 #pragma mark - Protocol implementation 'TDITransitionCustomTransform' //Conforms to "TDITransitionCustomTransform" protocol, return currrent image view state , by current layer - (UIImage*)imageForCurrentState { //Make print UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //return printed image return screenShot; } 

I thought this could work now because I am rendering this render in the converted view layer, which was transformed by myself ... And it didn’t work because “renderInContext:” does not receive layers of its subzones, is this possible?

Any interest in even more code for this solution can be found here . in the apple dev forum.

It may be a function error, or it is simply not intended for this purpose ...

0
source

Did you really try? I am currently working on a project with several 3D transforms, and when I try to programmatically take this screenshot, it works just fine :) Here is the code that I use:

 -(UIImage *)getScreenshot { CGFloat scale = 1.0; if([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) { CGFloat tmp = [[UIScreen mainScreen]scale]; if (tmp > 1.5) { scale = 2.0; } } if(scale > 1.5) { UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale); } else { UIGraphicsBeginImageContext(self.frame.size); } //SELF HERE IS A UIVIEW [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return screenshot; } 
0
source

Maybe you can use Core Graphaic instead of CATransform3DMakeRotation :)

 CGAffineTransform flip = CGAffineTransformMakeScale(1.0, -1.0); 

What gets effet on renderInContext

0
source

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


All Articles