I would like to create a camera view that takes a picture of the screen. Anything on the screen that is within its borders will be taken. This is not using the physical camera on the iPhone its basically a screen shot. I have attached a picture of what I am looking for. The camera view is the screen shot and the button takes the picture.
Considering a check for retina display use the following code snippet :
#import <QuartzCore/QuartzCore.h>
Your button click event should be like :
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.window.bounds.size);
}
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// use as a image in your app or you can save it in document directory for further usage
NSData *imageData = UIImagePNGRepresentation(image);
if (imageData) {
[imageData writeToFile:@"screenshot.png" atomically:YES];
} else {
NSLog(@"error while taking screenshot");
}
Is this using cocoapods?
Cocoa pods is totally different thing. In cocoa pods, also you can add this code snippet. Cocoa pods does not restrict you if you do code on your requirement.
and I just type this into a typical view controller?