How to get Screen Shot on button click


CODE 1
import "QuartzCore.framework"

// .h file
-(IBAction)captureScreen:(id)sender;


// .m file

#import <QuartzCore/QuartzCore.h>


-(IBAction)captureScreen:(id)sender
{
 UIGraphicsBeginImageContext(self.view.window.frame.size);
 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}




//Code 2
CGImageRef UIGetScreenImage(void);
CGImageRef originalImage = UIGetScreenImage();
CGImageRef videoImage = CGImageCreateWithImageInRect(originalImage,CGRectMake(0,66,320,230));UIImage *snapShotImage = [UIImage imageWithCGImage:videoImage];
UIImageWriteToSavedPhotosAlbum(snapShotImage, nil, nil, nil);
CGImageRelease(originalImage);                
CGImageRelease(videoImage); 

Comments

Popular posts from this blog

Hacker Rank problem solution

How to Make REST api call in Objective-C.

Building and Running Python Scripts with Xcode