0

I'm working on an application and I want to take the instant screenshot of my screen. I read some tutorials about that, and found this sort of solutions :

UIImageView * Test = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[[self.view layer] renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Test.image = screenShot;
[self.view addSubview:Test];

But this code doesn't give me the same thing as when on your device you push home and the other button to make a screenshot. How could i fix it please ?

EDIT : I have included QuartzCore/QuartzCore.h

  • 1
    See this http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically – Emmanuel Nov 24 '13 at 15:32
  • It doesn't do an exact screenshot as you could get by pushing home and the other button – user2947788 Nov 24 '13 at 17:02
  • What's different between the two screenshots? What components are on your screen? – rmaddy Nov 24 '13 at 18:08
  • FYI - don't hardcode the screen size and scale. Your code is only valid for a non-retina, 3.5" iPhone/iPod touch. – rmaddy Nov 24 '13 at 18:10
  • The difference is that i have a cube in 3D, done with CALayers, and i have only the initial view onto the screenshot even if i have put : [[self.view.layer presentationLayer] renderInContext:context]; It doesn't take in count rotations etc – user2947788 Nov 24 '13 at 19:25

0 Answers0