/*
* begin
* 可以通过下边这段代码实现将myView中的图像抓取并保存成文件
*/
UIGraphicsBeginImageContext(photoBackGround.frame.size); //@ 这里的myView可以换成其他的View,都可以得到这个View里的图像
CGContextRef context = UIGraphicsGetCurrentContext();
[photoBackGround.layer renderInContext: context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
static int i =0;
// UIGraphicsBeginImageContext(b.frame.size); //@ 这里的myView可以换成其他的View,都可以得到这个View里的图像
// CGContextRef context = UIGraphicsGetCurrentContext();
// [myView.layer renderInContext: context];
// UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
CGImageRef image = CGImageCreateWithImageInRect(theImage.CGImage,
CGRectMake(photoBackGround.frame.size.width/2, photoBackGround.frame.size.height/2,
photoBackGround.frame.size.width/2, photoBackGround.frame.size.height/2));
NSString *fileName = [NSString stringWithFormat:@"ss%d.png",i];
NSString* path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:fileName];
[UIImagePNGRepresentation([UIImage imageWithCGImage:image]) writeToFile:path atomically:YES];
i++;
* begin
* 可以通过下边这段代码实现将myView中的图像抓取并保存成文件
*/
UIGraphicsBeginImageContext(photoBackGround.frame.size); //@ 这里的myView可以换成其他的View,都可以得到这个View里的图像
CGContextRef context = UIGraphicsGetCurrentContext();
[photoBackGround.layer renderInContext: context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
static int i =0;
// UIGraphicsBeginImageContext(b.frame.size); //@ 这里的myView可以换成其他的View,都可以得到这个View里的图像
// CGContextRef context = UIGraphicsGetCurrentContext();
// [myView.layer renderInContext: context];
// UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
CGImageRef image = CGImageCreateWithImageInRect(theImage.CGImage,
CGRectMake(photoBackGround.frame.size.width/2, photoBackGround.frame.size.height/2,
photoBackGround.frame.size.width/2, photoBackGround.frame.size.height/2));
NSString *fileName = [NSString stringWithFormat:@"ss%d.png",i];
NSString* path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:fileName];
[UIImagePNGRepresentation([UIImage imageWithCGImage:image]) writeToFile:path atomically:YES];
i++;