2
votes

I'm using core-plot library to draw graphs. For some animation I have to take the image snapshot of the entire screen in order to make it smooth. The problem is that when I try to get image from the graph. The graph is always upside down. If I took only the graph itself as the snapshot, then it wouldn't be a problem - i could easily apply a transform on it. The problem is, I'm animating the whole screen, so that I take the snapshot of the entire UIWindow which consists the graph in one of its subviews. I tried it with the coreplot 0.2.2 sample available in coreplot project on code.google. I simply added one button to the window (so that it is visible on each tab), when the button is pressed, I take the image from the window content and save is as an image in the Album library using this code:

  
UIView *window = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(window.frame.size);
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, nil, NULL, NULL);

The result is as described above. Graph in the generated image is rendered upside down compared to the one that is visible on the screen. Do I do sth wrong or that's core-plots bug?

2

2 Answers

6
votes

Momentarily changing transform would help only for my animation. Still when putting application to background, Apple does snapshot of the application and here it would still look weird.

What I have done and what worked for me: I replaced lines:

self.layer.sublayerTransform = CATransform3DMakeScale(1.0, -1.0, 1.0);

from -initWithFrame: and -awakeFromNib in file CPLayerHostingView.m with the following one:

self.layer.transform = CATransform3DMakeScale(1.0, -1.0, 1.0);

Now it works and looks like a charm.

0
votes

Yup, this is a design decision made by the core plot people that's caused a ton of problems for me, when I try to do exactly what you're doing there. Best course of action is just to apply a transform to flip the core plot view upside down before you grab the image, then un-transform the view after you render the image.