Add the Framework : QuartzCore.framework
.h File:
#import <QuartzCore/QuartzCore.h>
.m File (Button for CaptureImage):
//Coding for Screen Shot for View(saved to Photo Library in Your Device)
UIGraphicsBeginImageContext(self.view.frame.size);
[[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Save Image to Local Library
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error)
{
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
}
[alert show];
}
Add the Framework : QuartzCore.framework
.h File:
#import <QuartzCore/QuartzCore.h>
.m File (Button for CaptureImage):
//Coding for Screen Shot for ScrollView (saved to Photo Library in Your Device)
UIImage * screenshot;
UIGraphicsBeginImageContext(myScrollView.contentSize);
{
CGPoint savedContentOffset = myScrollView.contentOffset;
CGRect savedFrame = myScrollView.frame;
myScrollView.contentOffset = CGPointZero;
myScrollView.frame = CGRectMake(0, 0, myScrollView.contentSize.width,
myScrollView.contentSize.height);
[myScrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
screenshot = UIGraphicsGetImageFromCurrentImageContext();
myScrollView.contentOffset = savedContentOffset;
myScrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
//Save Image to Local Library UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error)
{
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
}
[alert show];
}
No comments:
Post a Comment